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 using legend columns=-1 to make a horizontal legend. However, the distance between the individual legend entries is too small for my taste. Is there a straightforward way to increase the horizontal spacing between individual legend entries?

share|improve this question
add comment

1 Answer

up vote 25 down vote accepted

The legend is a TikZ matrix, so you can use the styles that apply to general matrices to influence the appearance.

In the legend matrix, the sample image and the entry text each occupy their own cell, so we have to increase the spacing for every second cell. For this, we can use the every even column style: By setting the column sep value of the matrix to a larger value for every second column, the horizontal spacing between the legend entries is increased without changing the distance between the image and the text.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend columns=-1,
legend entries={Long plot title, B, C},
legend style={/tikz/every even column/.append style={column sep=0.5cm}}]

\addplot{-x^3};
\addplot{-35*x^3};
\addplot{-6*x^3};

\end{axis}

\end{tikzpicture}
\end{document}

Spacing between columns in pgfplots legend

To adjust the spacing between rows of entries, we don't need to jump through the every even column/.append style hoop. Instead, we can just say legend style={row sep=0.5cm}.

share|improve this answer
    
Works nicely, thanks! –  Jannik Jochem May 13 '11 at 15:55
add comment

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.