pgfplots: Weird problem when using `\addlegendentry` with line break
manuel-kuehner opened this issue · comments
See https://tex.stackexchange.com/questions/636298 (incl. screenshot)
- I want to have an additional multi-line custom entry in the legend (
\addlegendentry
). - Therefore, I follow https://tex.stackexchange.com/questions/204395/.
- I also want the legend to be left-aligned.
- Somehow, I need both (seemingly redundant) following lines to make it work:
legend style = {
cells = {align = left}, % When commented out then error occurs
},
legend cell align = {left},
- If I remove
cells = {align = left},
the I get an error. - If I remove
legend cell align = {left},
then the alignment is centered.
\documentclass[12pt,letterpaper,landscape]{article}
\usepackage{mathtools}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
legend style = {
cells = {align = left}, % When commented out then error occurs
},
legend cell align = {left},
]
% Plot A
\addplot{x^2 - x + 4};
\addlegendentry{$T_\text{R, I}$}
% ---
% https://tex.stackexchange.com/questions/204395/
\addlegendimage{empty legend}
\addlegendentry{
Line 1\\
Line 2
}
\end{axis}
\end{tikzpicture}
\end{document}
See my answer to your question on TeX.SX.