0

It seems that fractions are placed too low within the legend in pgfplot. In my opinion, the fraction is placed a bit too low, therefore, the distance to the upper legend entry is too wide and to the lower, it is too narrow.

E.g. in this MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture} 
\begin{axis}[domain=1:2]
  \addplot {x^2 };\addlegendentry{$x^2$}; 
  \addplot {1/x};\addlegendentry{$\frac{1}{x}$}; 
  \addplot {x};\addlegendentry{$x$}; 
\end{axis}
\end{tikzpicture}
\end{document}

which results in:enter image description here

Is this a bug? And is it possible to adjust the spacings?

1

It appears that the text is aligned from the top down rather than from the baseline, and the image is placed independently (ignoring the baseline). One can compensate using the optional arguments of \raisebox to change the height. The value needed appears to be twice the default inner sep.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture} 
\begin{axis}[domain=1:2]
  \addplot {x^2 };\addlegendentry{$x^2\mathstrut$}; 
  \addplot {1/x};\addlegendentry{\raisebox{0pt}[.666em]{$\frac{1}{x}$}}; 
  \addplot {x};\addlegendentry{$x\mathstrut$}; 
\end{axis}
\end{tikzpicture}
\end{document}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.