0

The title says it all. I have a tikzplot. I have a legend. And I have some content that is too big for the legend box. Please help. This is my code:

\begin{figure}[H]
    \centering
    \begin{tikzpicture}
        \begin{axis}%
            [     
            xmin=-7,
            xmax=7,
            axis x line=bottom,
            ymax=7,
            axis y line=middle,
            axis x line=middle,
            domain=-7:7,
            legend style={at={(0.7,0.9)}}     ,
            ylabel=$y$,
            xlabel=$x$,
            ]
            \addplot[red,mark=none]{(x>=0)*x};
            \legend{$   f(x)=\left\{\begin{array}{lll}
                    0 & \text { for } & x<0 \\
                    x & \text { for } & x \geq 0
                \end{array}\right.$}
        \end{axis}
    \end{tikzpicture}
\end{figure}
0

1 Answer 1

1

This uses the \tiny font, reduces the spacing between array columns, and locates the legend (north west corner) out of the way.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}%
            [     
            xmin=-7,
            xmax=7,
            axis x line=bottom,
            ymax=7,
            axis y line=middle,
            axis x line=middle,
            domain=-7:7,
            legend style={at={(axis cs: -0.4,5.4)},font={\tiny\arraycolsep=2pt}},
            ylabel=$y$,
            xlabel=$x$,
            ]
            \coordinate (A) at (axis cs: -6,6);
            \addplot[red,mark=none]{(x>=0)*x};
            \legend{$ f(x)=\left\{\begin{array}{lll}
                    0 & \text{for} & x<0 \\
                    x & \text{for} & x \geq 0
                \end{array}\right.$}
        \end{axis}
    \end{tikzpicture}
\end{document}
1
  • Thank you so much <3
    – anon
    Commented Jun 16, 2022 at 14:53

You must log in to answer this question.