# pgfplots legend wrong order

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}

\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}
]
\legend{
\strut $A$,
\strut $B$,
\strut $C$,
\strut $D$,
\strut $E$,
\strut $F$,
}
\end{axis}
\end{tikzpicture}

\end{document}


What I get is:

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

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
},
]
\strut $A$,
\strut $B$,
\strut $C$,
\strut $D$,
\strut $E$,
\strut $F$%     <-- removed the comma