15

In some of my plots the curve description in the legend is too long, making the legend going over the plot, even if the legend is placed as far away as possible. Therefore I want to have multiple lines in the legend, but

\addlegendentry{a\\ b} 

results in an error. Is there another way to do that?

0

1 Answer 1

21

By default, TikZ nodes do not allow line breaks, but if you add the align=<left/right/center> key you can use \\. Hence, you can modify the legend style as below.

\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};
\end{axis}
\end{tikzpicture}
\end{document}
0

You must log in to answer this question.

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