pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.

Home Page:http://pgfplots.sourceforge.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.