对于以下 MWE,我想:
- 将长条目的图例图像与其文本置于中心,
- 展开图例框以包含其条目,
- 并根据图例宽度将第二行条目置于中心。
。
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={([yshift=30pt]0.5,1)},anchor=north,
text width=1in,
cells={align=left},
minimum height=2mm
},
legend columns=3,
xmin=0, xmax=10,
ymin=0, ymax=10,
]
\addplot [red, line width = 5pt, domain=0:10] {x};
\addlegendentry{$x$}
%
\addplot [black, line width = 5pt, domain=0:10] {(x-5)^2};
\addlegendentry{$(x-5)^2$}
%
\addplot [yellow, line width = 5pt, domain=0:10] {10-(x-5)^2}; \addlegendentry{$10-(x-5)^2$}
%
\addplot [orange, line width = 5pt, domain=0:10] {10-x};
\addlegendentry{$10-x$}
%
\addplot [green, line width = 5pt, domain=0:10] {5};
\addlegendentry{long long long long long entry}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这是解决前两个问题或您的愿望的部分答案。
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={([yshift=30pt]0.5,1)},anchor=north,
text width=1in,
cells={align=left},
minimum height=2mm
},
legend columns=3,
xmin=0, xmax=10,
ymin=0, ymax=10,
]
\addplot [red, line width = 5pt, domain=0:10] {x};
\addlegendentry{$x$}
%
\addplot [black, line width = 5pt, domain=0:10] {(x-5)^2};
\addlegendentry{$(x-5)^2$}
%
\addplot [yellow, line width = 5pt, domain=0:10] {10-(x-5)^2}; \addlegendentry{$10-(x-5)^2$}
%
\addplot [orange, line width = 5pt, domain=0:10] {10-x};
\addlegendentry{$10-x$}
%
\addplot [green, line width = 5pt, domain=0:10] {5};
\addlegendentry{\begin{minipage}[b]{1in}
long long long
long long entry\end{minipage}}
\end{axis}
\end{tikzpicture}
\end{document}
我甚至没有尝试解决第三个问题,因为我认为结果看起来不太好,但这只是我的个人观点。或者,我可能会使用
\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style={
at={([yshift=30pt]0.5,1)},anchor=north,
text width=1in,
cells={align=left},
minimum height=2mm
},
legend columns=3,
xmin=0, xmax=10,
ymin=0, ymax=10,
]
\addplot [red, line width = 5pt, domain=0:10] {x};
\addlegendentry{$x$}
%
\addplot [black, line width = 5pt, domain=0:10] {(x-5)^2};
\addlegendentry{$(x-5)^2$}
%
\addplot [yellow, line width = 5pt, domain=0:10] {10-(x-5)^2}; \addlegendentry{$10-(x-5)^2$}
%
\addplot [orange, line width = 5pt, domain=0:10] {10-x};
\addlegendentry{$10-x$}
%
\addplot [green, line width = 5pt, domain=0:10] {5};
\addlegendentry{\begin{minipage}[b]{3in}
long long long
long long entry\end{minipage}}
\end{axis}
\end{tikzpicture}
\end{document}
我认为它看起来足够好了。