2

If I have a legend using PGFPlots too long near the right margin of the document I can not see part of it. How can I insert a line break inside the legend, or adjust the length? (The legend is on the outside of the graph). For example:

\addlegendentry{$\text{IntegralNumérica1 }=\text{ ResuelveEDO}(x+y^2,\;0,\;0\;2\;0.1)}

Legend Box

Is there any way to do something like this?:

\addlegendentry{$\text{IntegralNumérica1 }=$ \\ $\text{ ResuelveEDO}(x+y^2,\;0,\;0\;2\;0.1)$}

I tried adding legend style={line width=2.8pt} in the axis environment but produces error.

Any help? Thanks!

EDIT: MWE:

\documentclass[11pt]{article}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, patterns}
\pgfplotsset{compat=1.8}
\pgfplotsset{
  Cus/.style={
        axis equal image,
        axis lines = center,
        xlabel = $x$,
        ylabel = $y$,
        view={0}{90},
    }
}

\begin{document}

\begin{tikzpicture}[scale=0.75]
    \begin{axis}[
        Cus,
        xmin=-4.1, xmax=4.1,
        ymin=-5.1, ymax=4.1,
        xtick={-4,-2,...,4}, ytick={-6,-4,...,4},
        samples=20,
        legend pos=outer north east
        ]
        \addplot[very thick,red] {x^2};
        \addlegendentry{$\text{BlablablablablablablablablablablaBlablablablablablablablablablablaBlablablablablablablablablablabla}$}
    \end{axis}
\end{tikzpicture}

\end{document}

Legend Error

EDIT 2: I forgot to mention that I have more than one legend.

4
  • 1
    please provide small, complete document with your pgfplots diagram, which show your problem.
    – Zarko
    Mar 19, 2018 at 23:26
  • You prevent line breaks by putting everything into a math environment. \addlegendentry{$\text{IntegralNumérica1 }=$ $\text{ ResuelveEDO}(x+y^2,\;0,\;0\;2\;0.1)}$ should already do the line break.
    – user121799
    Mar 19, 2018 at 23:41
  • @Zarko Added MWE.
    – manooooh
    Mar 19, 2018 at 23:43
  • Hello @marmot, I promised you that I would take you out of your hibernation state hahaha. Does not work :(
    – manooooh
    Mar 19, 2018 at 23:46

1 Answer 1

2

Sorry for my wrong comment. And sorry, I guided you in the wrong direction. Your question is quite likely a duplicate of those leading to this answer and that answer, which however seem not to be duplicates of another.

\documentclass[11pt]{article}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta, patterns}
\pgfplotsset{compat=1.15}
\pgfplotsset{
  Cus/.style={
        axis equal image,
        axis lines = center,
        xlabel = $x$,
        ylabel = $y$,
        view={0}{90},
    }
}

\begin{document}

\begin{tikzpicture}[scale=0.75]
    \begin{axis}[
        Cus,
        xmin=-4.1, xmax=4.1,
        ymin=-5.1, ymax=4.1,
        xtick={-4,-2,...,4}, ytick={-6,-4,...,4},
        samples=20,
        legend pos=outer north east,
         legend style={cells={align=left,anchor=west}}
        ]
        \addplot[very thick,red] {x^2};
        \addlegendentry{Maecenas eu tortor\\ eu diam fringilla\\
         scelerisque sit\\ amet eget enim.\\
Nam vitae bibendum erat,\\ sit amet scelerisque\\ felis. Suspendisse placerat\\
vitae velit pharetra\\ lobortis et marmottae. }
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

5
  • Add to that that I forgot to mention that I have more than one legend... So I am adding the parameters that are between [...] to each addlegendentry, and modifying both to fit them to my original document. Laborious work :P
    – manooooh
    Mar 20, 2018 at 0:51
  • @manooooh Sorry again, and please have a look at my revised answer.
    – user121799
    Mar 20, 2018 at 5:19
  • Lol I search for a possible duplicate (here and Google) but I couldn't find anything. Thanks again, it works for me, and don't worry for the wrong comment
    – manooooh
    Mar 20, 2018 at 5:56
  • @manooooh So did I, and couldn't find the others at first either. Google picture search finally led me to the above links. Interestingly, both question happily coexisted till now without being marked as duplicates. The criteria for being a duplicate are not clear to me, see e.g. here.
    – user121799
    Mar 20, 2018 at 12:34
  • I red that thread and the discussion, for me is fine to close a question for being a duplicate, like this one. If we don't have organization we are nothing! Idk why both questions are still open O.o
    – manooooh
    Mar 20, 2018 at 17:18

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