TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 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.