1

I'm having difficulties with setting the order of the legend entries in the following 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}

What I get is:

enter image description here

This is not the order I specified the entries, neither when filling the legend row by row nor when filling column by column.

What I want would be:

A C E
B D F

which is the order I specified the entries, written column by column into the legend.

  • Does my answer answer your question? If yes, please consider upvoting it (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). Otherwise please let us know. Thank you. – Stefan Pinnow Feb 27 '18 at 5:36
  • Your answer is fine. Please consider updating it if the issue gets fixed :) – Christoph90 Feb 27 '18 at 18:01
  • Thank you for accepting. And of course I'll update it when the issue is fixed. – Stefan Pinnow Feb 27 '18 at 18:26
2

I think you have found a bug here. But if you remove the trailing comma in the \legend list everything seems to work fine.

Alternatively you could use \addlegendentrys instead of \legend.
(\legend has higher precedence than \addlegendentry, so in the below code this is not a problem.)

(For the record: I filed this in the PGFPlots Tracker as bug 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}

image showing the result of above code

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.