pgfplots圖例順序錯誤

pgfplots圖例順序錯誤

我在設定以下 MWE 中圖例條目的順序時遇到困難:

% !TeX program = lualatex
\RequirePackage{luatex85}
\documentclass[border=1pt]{standalone}

\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{siunitx}

\usepackage[partial=upright]{unicode-math}
\usepackage{fontspec}

\usepackage{xcolor}

\usepackage{tikz}
\usepackage{pgfplots}
    \pgfplotsset{compat=newest}

\usepackage[main=ngerman,english]{babel}

\begin{document}

    \begin{tikzpicture}
        \begin{axis}[
            scale only axis,
            width=0.475\linewidth,
            height=5cm,
            xmin=0,
            xmax=1,
            ymin=0,
            ymax=10,
            legend style={
                at={(0.55,0.95)},
                anchor=north,
                transpose legend,
                legend columns=3,
                legend cell align=left,
                draw=none % Unterdrücke Box
            },
            cycle multiindex* list={
                color list\nextlist
                mark list*\nextlist}
        ]
        \addplot {x};
        \addplot {2*x};
        \addplot {3*x};
        \addplot {4*x};
        \addplot {5*x};
        \addplot {6*x};
        \addplot {7*x};
        \legend{
            \strut $A$,
            \strut $B$,
            \strut $C$,
            \strut $D$,
            \strut $E$,
            \strut $F$,
        }
        \end{axis}
    \end{tikzpicture}

\end{document}

我得到的是:

在此輸入影像描述

這不是我指定條目的順序,無論是在逐行填充圖例時還是在逐列填充圖例時。

我想要的是:

A C E
B D F

這是我指定條目的順序,逐列寫入圖例中。

答案1

我想你在這裡發現了一個錯誤。但如果您刪除清單中的尾隨逗號,\legend一切似乎都可以正常工作。

或者,您可以使用\addlegendentrys 而不是\legend
\legend優先級高於\addlegendentry,因此在下面的程式碼中這不是問題。)

(鄭重聲明:我在 PGFPlots Tracker 中將其歸檔為錯誤201.)

% used PGFPlots v1.15
\documentclass[border=1pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        scale only axis,
        width=0.475\linewidth,
        height=5cm,
        xmin=0,
        xmax=1,
        ymin=0,
        ymax=10,
        legend columns=2,
        transpose legend,
        legend style={
            at={(0.55,0.95)},
            anchor=north,
            legend cell align=left,
            draw=none % Unterdrücke Box
        },
        cycle multiindex* list={
            color list\nextlist
            mark list*\nextlist
        },
    ]
        \addplot {x};       \addlegendentry{A}
        \addplot {2*x};     \addlegendentry{B}
        \addplot {3*x};     \addlegendentry{C}
        \addplot {4*x};     \addlegendentry{D}
        \addplot {5*x};     \addlegendentry{E}
        \addplot {6*x};     \addlegendentry{F}
        \addplot {7*x};     \addlegendentry{G}

        \legend{
            \strut $A$,
            \strut $B$,
            \strut $C$,
            \strut $D$,
            \strut $E$,
            \strut $F$%     <-- removed the comma
        }
    \end{axis}
\end{tikzpicture}
\end{document}

顯示上述程式碼結果的圖像

相關內容