The height  of the liquid column in the tube is constrained by the hydrostatic pressure and by the surface tension. The following derivation is for a liquid that rises in the tube; for the opposite case when the liquid is below the reference level, the derivation is analogous but pressure differences may change sign.