1

How can I shift the line/marker (that shows the color of the curve) in the first line of a multi line legend entry?

    \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}

enter image description here

1 Answer 1

2

Rather then insert multi line legend entry you can put entry a and c in single line and add \addlegendimage{empty legend} for legend entry b and 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}

Or to control vertical alignment of legend entry you can add 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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .