7

I would like to adjust the width of the legend lines (images) in PGFplots. Since legend is a TikZ matrix, I can adjust the separation between lines, space between text and lines by changing the matrix style. I tried to find a matrix style property to change the width of each cell (here the cell where legend lines are positioned in), but could not find any answer for that too. This is a sample code:

\documentclass{article}
\usepackage{pgfplots}

\pgfplotsset{
    compat=newest,
    plot coordinates/math parser=false,
    every axis/.append style={
        tick label style={font=\scriptsize}, % new bit
        label style={font=\scriptsize}, % new bit
        legend style={font=\scriptsize,row sep=-0.1cm,/tikz/every odd column/.append style={column sep=0.01cm}},% new bit
        xlabel shift=0.5em,
        ylabel shift=-0.5em
    }
}
\begin{document}

\begin{tikzpicture}
    \begin{axis}[%
        xlabel={XLABEL},
        ylabel={YLABEL},
        axis lines*=left,
        ylabel absolute, ylabel style={yshift=-1em}]
        \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

So my question is how to adjust the lines (images) in a legend?

0

1 Answer 1

10

If I understand correctly, you're not trying to adjust the width of the legend column that contains the lines, but rather you're trying to increase the length of the lines themselves. You can do that by adding legend image post style={xscale=2} to your axis options:

\documentclass{article}
\usepackage{pgfplots}

\pgfplotsset{
    compat=newest,
    every axis/.append style={
        legend image post style={xscale=2}
    }
}
\begin{document}

\begin{tikzpicture}
    \begin{axis}
        \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}
1
  • Yes, Thank you! I actually wanted to change the width of the line, though thought that it might be possible by changing the width of the column containing the lines. Anyways, your solution is what I wanted to do.
    – M.Reza
    Jan 15, 2013 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .