如何移动多行图例条目第一行的线/标记(显示曲线的颜色)?
\documentclass[border=4pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.12
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={cells={align=left}}
]
\addplot {rnd};
\addlegendentry{a\\b};
\addplot {rnd};
\addlegendentry{c\\d};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以将条目 a 和 c 放在一行中,然后添加\addlegendimage{empty legend}
图例条目 b 和 d,而不是插入多行图例条目
\documentclass[border=4pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend style={cells={align=left}}]
\addplot {rnd};
\addlegendentry{a}
\addlegendimage{empty legend}
\addlegendentry{b}
\addplot {rnd};
\addlegendentry{c}
\addlegendimage{empty legend}
\addlegendentry{d}
\end{axis}
\end{tikzpicture}
\end{document}
或者控制图例项的垂直对齐方式,您可以添加legend style={nodes={yshift=-.5\baselineskip}}
\documentclass[border=4pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={cells={align=left},nodes={yshift=-.5\baselineskip}}
]
\addplot {rnd};
\addlegendentry{a\\b};
\addplot {rnd};
\addlegendentry{c\\d};
\end{axis}
\end{tikzpicture}
\end{document}