The focus produced by caffeine is enhanced by theanine (or L-theanine), which also counteracts jitters/headaches caffeine can otherwise induce. You can buy theanine in capsule form. Take 1-2 times as much theanine as caffeine. So for a cup of coffee (either brewed, or containing 2 shots espresso), which contains roughly 150mg caffeine, take say 200mg theanine.
You probably shouldn’t routinely have more than 1 cup of (caffeinated) coffee a day if you want to avoid becoming tolerant of it, which removes its effects. And don’t drink it in the afternoon or evening, to avoid disturbing your sleep (which may not be obvious, as your sleep can be disturbed even if you have no trouble falling asleep).
Alternatively drink tea, which has far less caffeine than coffee—so you can have as many cups as you like. Tea also contains some theanine (though rather less than the optimal dose).