Let’s briefly go through how TeX creates a fraction (many details will be ignored for the sake of simplicity). First, TeX needs to know where the fraction bar should be drawn and how thick it should be. These are controlled by \fontdimen parameters, which are decided by the font designer(s) (but users can change them later). The vertical position of the bar corresponds to \fontdimen 22 of family 2, while the thickness corresponds to \fontdimen 8 of family 3. Then, TeX needs to shift the numerator and denominator up and down from the “baseline” in order to stack them into a fraction. The parameters controlling numerator are \fontdimen 8, 9, 10 of family 2, while those for denominator are \fontdimen 11, 12 of family 2. Note: It is up to the font designer(s) to set appropriate values to these parameters so the results will be visually pleasing in most cases.
Is there a reason for this behaviour
This is because mathpazo uses identical values for many parameters as Computer Modern Math does. These values work fine with Computer Modern (and also Latin Modern lmodern). But Palatino-like designs have taller “bodies”, which often need more generous spacing. So these shifting amounts (designed for Computer Modern) are probably not adequate for Palatino.
and can one adjust the position of the line?
You don’t really want to adjust the position of the fraction bar (because \fontdimen 22 of family 2 affects a lot of other different things). Instead, you can enlarge \fontdimen 11, 12 of family 2 to cause the denominator to be shifted down a bit more.
David’s answer shows how you can assign new values to \fontdimen11\textfont2. The drawback is that this assignment is very low-level (the lowest level of TeX programming). In particular, this only works for one font size (namely, the \normalsize 10pt in this case).
A slightly higher-level solution is to use \DeclareFontShape within the LaTeX NFSS (New Font Selection Scheme). The syntax is
\DeclareFontShape{<encoding>}{<family>}{<series>}{<shape>}
{
<size declarations>
}
{
\fontdimen11\font=<some proportion of>\fontdimen6\font
...
}
But IMO this sort of code should appear in packages. Well, IMO this sort of code should never be needed if the parameters in the font were adequate in the first place.
I don’t think that it should be like this, since when using lmodern instead, the bar is (as far as I can tell) exactly in the middle
Well, just as David’s answer also explained, if the bar is exactly in the middle of 1 and 2, then it certainly cannot be in the exact middle of 1 and x, nor can it be in the exact middle of 1 and (N). Remember, it’s about visual balance in an infinite number of cases, not about mathematical exactness.
My recommendation
Switch to newpxtext and newpxmath if you can. These newer packages are actively maintained. I also helped refine newpxmath in 2019, which dealt with the positions of numerator and denominator. The details are here: https://tex.stackexchange.com/a/509092 which IMO suit your current need as well. I tried to find balance between (1) equalized spacing around the fraction bar, (2) uniform baseline for numerator, and (3) uniform baseline for denominator. It can never be “perfect”, but I think the results are visually pleasing.
In conclusion, just use \usepackage[fracspacing]{newpxmath} instead of \usepackage{mathpazo} should do the trick.
If you want to stick with mathpazo, then:
If you still want to use mathpazo, then here is the LaTeX NFSS code you can use:
\documentclass{article}
\usepackage{mathpazo}
% The original declarations can be found in omszplm.fd
% We are changing them to use our customized fontdimen's
\DeclareFontFamily{OMS}{zplm}{
\skewchar\font=48 % kept from the original file
\fontdimen 8\font=0.789\fontdimen6\font % 0.789 of a quad
\fontdimen11\font=0.798\fontdimen6\font % 0.798 of a quad
}
\DeclareFontShape{OMS}{zplm}{m}{n}{<-> zplmr7y}{}
\DeclareFontShape{OMS}{zplm}{b}{n}{<-> zplmb7y}{}
\DeclareFontShape{OMS}{zplm}{bx}{n}{<->ssub * zplm/b/n}{}
\begin{document}
Inline $\frac{1}{2}$ and display
[ \frac{1}{2} ]
\end{document}
The two values 0.789 and 0.798 are taken from newpxmath. If memory serves me correctly, they should be adequate for Palatino’s long ascenders and descenders. You are welcome to adjust them to your need, and even adjust \fontdimen 9, 10, 12 as well.
mathpazofont package hasn't been updated in years. Are you free to switch to a different Palatino-type set of font packages? If so, you may want to look into thenewpxtextandnewpxmathpackages, especially as they leave a tad more space between the fraction bar and the denominator. – Mico Aug 31 '21 at 10:16newpxmathalmost two years ago: https://tex.stackexchange.com/a/509092 and I think you'd agree that the spacing was improved significantly:)– Ruixi Zhang Aug 31 '21 at 13:02\fontdimenparameters frommathpazo, I’d call them “non-choices”. Many parameters are directly inherited from Computer Modern Math, without being adjusted for the taller body of Palatino-like designs. – Ruixi Zhang Aug 31 '21 at 13:18