mwe 是
\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}
两个图例的长度不同,并且它们垂直居中对齐。现在我想将图例左对齐。我该怎么做?
答案1
您只需要添加到轴选项:(legend cell align=left
参见包 PGFPLOTS 手册,第 255 页):
\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}