For a diagram of a real situation please see the picture below.
The way the archer fish overcomes the light refraction at the interface water-air has been a difficult question for scientists since 1900. First answer to this question was given around the year 1935 when it was suggested that the archer fish spits a jet of water at his pray, from a position where the pray appears to be nearly vertical to his eyes. This way, the line of sight to his pray is nearly perpendicular to the water-air interface such that light does not undergo refraction.
Although this is a good explanation, in reality the archer fish spits the water jet when his is at some horizontal distance from his pray, and therefore there is pronounced diffraction of the light. Day by day observations of his behavior before releasing the water jet have led to the following explanation of his targeting accuracy.
First he approaches the pray from a position under water that is near the surface. This way the distance d1 is very small. From this position, by rotating his eyes and focusing the light he measures the horizontal distance d to the prey. Since d1 is very small, d can be considered as the horizontal distance from the refraction point to the pray. Knowing this distance, and the way light refracts above the water, he makes corrections for the spitting angle such that the jet of water is directed toward the real point A rather that toward the false point B.
In reality, the fish is no mathematician so that he makes a lot of trial and error jet spitting at the tip of a branch from a position under water situated at a known horizontal distance d until he learns the correct angle where to aim for that particular distance d.