# Multi-line legend entry in pgfplots

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?

• Could you provide a MWE, please ? – flav Nov 26 '15 at 10:22
• @flav: Is it still needed? – arc_lupus Nov 26 '15 at 10:36

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