A diagram showing the moon directly between the earth and the sun is key here. If we call the radii of the sun and the moon rs and rm and the distances from earth Ds and Dm. respectively, there are similar triangles which can be analysed. the hypotenuse of both of the triangles is a straight line from earth tangential with both the moon and the sun, let the angle between this hypotenuse and the line of centres be 'a'. It is clear that tan(a) = rs/Ds = rm/Dm therefore rm=Dm*rs/Ds.