check for correct driver for your graphic card on nvidia page . download it and start manual installation. read nvidia readme and installation guide.
before installation or re-installation check compiler version. linux kernel is normally compiled with gcc so should be nvidia driver.
if this is a re-installation make sure it is clean system.
sudo apt-get --purge remove nvidia-340 (remove old driver)
nvidia NVIDIA-Linux-x86_64-xxx.yyy.run script is using cc for compiling. check version of cc with command cc --version it should be at same version an level as was used to compile the linux kernel.
cc is a link target to gcc. use command sudo update-alternatives --config gcc to select correct version for the gcc. cc can point to clang an that case is necessary to replace the cc link target with command: sudo update-alternatives --config cc
install nvidia kernel driver with command: sudo apt-get install nvidia-340 or manualy run NVIDIA-Linux-x86_64-xxx.yyy.run script as root user.
check is display is using nvidia driver with command: sudo lshw -C display.
check if nvidia driver is in use :lspci -k | grep -EA3 'VGA'
after instalation generate proper xorg.conf file with command sudo nvidia-xconfig. normally nvidia-xconfig set proper value of DPI for your monitor.
to adopt proper DPI setting for your monitor specify your desired DPI by placing desired value inside section "Monitor" of your /etc/X11/xorg.conf. for example: Option "DPI" "96 x 96"
logout an login to apply new settings for the X server.