Look at the striker on all doors and check that the bolts are tight (torx bit), preferably torqued to spec with a torque wrench, and that the point of contact where the latch locks onto the striker isn't worn down. If it is worn enough that it might be the problem, you can usually flip the striker over and use the non-worn side.
If the strikers are good the next thing to check would probably be the door hinge pins themselves, without messing with the hinge bolts yet. The door hinge pins wear (usually just one wears, actually) and replacing a worn one can put a door right back in to perfect alignment. If you mess with hinge bolts instead, it can take a loooong time to ever get the door back into perfect alignment ever again, even when the hinge pins are replaced afterward.
You can get new hinge pins from Autozone or any auto parts store in the HELP! section.
You should also check the weatherstripping, rubber door bumpers at the top and bottom corners, scuff plates, and all the plastic interior trim to be sure that nothing is out of place or otherwise interfering with the door and causing the gap. Also check that the latches are clean and lubed and it's not just sticky latches that aren't snappy and letting the door close and shut tightly.
You should also do some visual inspection, eyeing the door (including the top part) from the extreme angles like you show in the pic and try to get an idea of whether the door and body is otherwise straight top to bottom or if anything else is out of place. Have someone push in the door slightly to it's ideal position and hold it there while you're inspecting the body lines if need be. It could be that someone pushed in the door panel ever so slightly with their vehicle, or other ultra-mild body "damage" is causing the gap.
You can also just look at the door hinges with a flashlight and see if there is any evidence that they moved - either the hinges on the body or on the door. Hinges can also sag/bend slightly over time so sometimes even with a hinge pin replacement, tweaking hinges slightly may be necessary. Loosening the bolts and moving the entire door on the hinges isn't the same thing as tweaking the hinges by bending the tabs where the pins go, since when you loosen the hinge bolts and move the door, you're changing the angle of the entire door.
So, I'd say check everything and do a lot of other stuff before ever touching the hinge bolts, only loosening those if the hinges are slightly moved from their original position (unlikely), or you've done everything else and no other adjustments have worked.