Change your targetting priority to cone instead of "ignore depth" or whatever it is by default that basically tends to go from left to right instead of front to back.
Also you can bind (or macro) another button that targets the closest enemy. Warmly suggested you use that if you want to get someone who's right on your face or if you want to reset your tab target back to frontal foes instead of pressing esc or cancel.