0

I have the following code, which brings me to the figure in the first image.

Now I would like to place the text (in this example: exp(x) and x²+2x+1) of the legend entries underneath the red and blue lines (like in the second Image) and not next to the lines.

\documentclass{article}

\usepackage{pgfplots} \usepackage{tikz}

\begin{document}

\begin{figure}[h] \centering \begin{tikzpicture} \begin{axis}[ ymajorgrids, xmin = 0, xmax = 8, ymin = 0, ymax = 100, legend style = {at = {(0.15,-0.2)}, anchor = west, draw = none}, legend columns = 2, ]

        \addplot[color=red]{exp(x)};
        \addlegendentry{exp(x)}
        \addplot [domain=-10:10, samples=100, color=blue] {x^2 + 2*x + 1};
        \addlegendentry{\(x^2 + 2x + 1\)}
    \end{axis}
\end{tikzpicture}

\end{figure}

\end{document}

Image 1

Image 2

Is there a simple way to achieve that?

Alex
  • 1
  • 1
    Somewhat related: https://tex.stackexchange.com/questions/54794/using-a-pgfplots-style-legend-in-a-plain-old-tikzpicture While the legend is implemented as a tabular, the side-by-side positioning is hard wired. – John Kormylo Oct 05 '23 at 00:11

0 Answers0