3

The mwe is

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot coordinates {(0,0) (1,1)};
    \addlegendentry{Short Legend}
    \addplot coordinates {(0,1) (1,2)};
    \addlegendentry{Very very long Legend}
  \end{axis}
\end{tikzpicture}
\end{document} 

The two legends have the different length and they vertical align at the center. Now I want to align the legend at the left. How can I do this?

4

You only need add to axis option :legend cell align=left (see Manual for Package PGFPLOTS, page255):

enter image description here

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[legend cell align=left]% <--- added 
    \addplot coordinates {(0,0) (1,1)};
    \addlegendentry{Short Legend}
    \addplot coordinates {(0,1) (1,2)};
    \addlegendentry{Very very long Legend}
  \end{axis}
\end{tikzpicture}
\end{document}
| improve this answer | |
  • Thanks @Zarko. I didn't read the manual carefully. Now I believe the manual is the best reference. – Ice0cean Jan 14 '17 at 3:36

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.