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 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?

share|improve this question
    
In its current form, your question might not receive many answers. Please take a look at the How to Ask-page and try to improve your question according to the guidance found there. This may require you to show some effort on your part in terms of attempting a solution. As you already point us to another question that might provide helpful information it would be nice if you could show some minimal working example (MWE) that shows what you already have tried and how far you got. –  Benedikt Bauer Jan 14 '13 at 9:24
add comment

1 Answer 1

up vote 6 down vote accepted

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}
share|improve this answer
    
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 '13 at 8:39
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.