Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to make the legend border tighter. What is the \begin{axis}[legend style={...}] property to adjust the legend border (both width and height of the border)?

\documentclass{article}
    \usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        legend columns=-1]
        \addplot+[mark=none] plot {x^2};
        \addlegendentry{a}
        \addplot+[mark=none] plot {1};
        \addlegendentry{b}
        \addplot+[mark=none] plot {x};
        \addlegendentry{c}
    \end{axis}
\end{tikzpicture}


\end{document}

enter image description here

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can use the legend style options, like so:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        legend style={inner xsep=0pt, inner ysep=0pt},
        legend columns=-1]
        \addplot+[mark=none] plot {x^2};
        \addlegendentry{a}
        \addplot+[mark=none] plot {1};
        \addlegendentry{b}
        \addplot+[mark=none] plot {x};
        \addlegendentry{c}
    \end{axis}
\end{tikzpicture}
\end{document}

Tighter Legend Border

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.