Distance from the water heater can be deceptive. The water most most likely branches off from a main pipe, and the branch point might be closer to the sink than the shower, even though if you are just walking through the house it’s the same distance.
Still, the distance from the water heater should effect how long it takes for the hot water to start running through the faucet, not how long the hot water lasts.
A shower will have a shorter amount of hot water minutes than a sink, because the shower has more water coming through it.
Your situation is a little screwy.
When you take a shower is it right after running the washing machine or dishwasher? Or, are you running those appliances at the same time as your shower?
I wonder if it is something with the fixture in your shower? Maybe it’s not completely opening the hot water side? If it’s a single handle, the apparatus inside can slip so to speak, and that will cause it to malfunction.