Graphics, Figures & TablesIncreasing line width of legend box for PGFplots

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Increasing line width of legend box for PGFplots

Post by drgz »

As the topic says, is there any way of increasing the line width of the legend box, without increasing the line width of each of the legend entry samples inside the box?

To change the legend style (taken from the PGF manual), one needs to include

Code: Select all

/pgfplots/legend style={desired options}
or alternatively

Code: Select all

every axis legend/.append style={desired options}
However, whenever I set

Code: Select all

legend style={line width=0.8pt}
also the line width of the legend entry samples is increased - which I'd like to avoid.

I'm looking for an option similar to the one that can be used for changing the options of the outer axis, i.e.

Code: Select all

outer axis line style={desired options}
but for the legend box - which I haven't found yet.

I've added a small example (taken from the PGF manual - but added some additional lines in order to show what I want to avoid):

Code: Select all

\documentclass[12pt,a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}
\thispagestyle{empty}

\begin{tikzpicture}
    \begin{axis}[
        xlabel=Index,
        ylabel=Value,
        outer axis line style={line width=0.8pt},
        legend entries={some function},
        legend style={nodes=right,line width=1.5pt}
     ]
    \addplot[color=blue,mark=*]coordinates{
        (1,8)
        (2,16)
        (3,32)
        (4,64)
        (5,128)
        (6,256)
        (7,512)
    };
    \end{axis}
\end{tikzpicture}
\end{document}
Any help is greatly appreciated!
Last edited by drgz on Fri Jun 25, 2010 9:12 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Increasing line width of legend box for PGFplots

Post by localghost »

Your sample has no legend [1]. The mentioned setting has the desired effect in my documents.

[1] View topic: Avoidable mistakes


Thorsten
drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Increasing line width of legend box for PGFplots

Post by drgz »

How can you say it got no legend? It is quite obvious that the following part of the code adds a legend entry (see page 112 in the PGF manual):

Code: Select all

legend entries={some function},
legend style={nodes=right,line width=1.5pt}
Just look at the PDF of the exact same code I posted in the first post... It's obvious that the option for increasing the legend line width also increases the line width of the sample, which is not what I want it to do; hence, I'm looking for a solution for increasing the line width of the legend box, but without affecting the sample line width.
Attachments
main.pdf
(23.76 KiB) Downloaded 434 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Increasing line width of legend box for PGFplots

Post by localghost »

I overlooked this part of code because I'm used to adding individual legend entries with the \addlegendentry command right after a plot command. Never mind. I can reproduce this effect. So I suggest to contact the package maintainer.
drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Increasing line width of legend box for PGFplots

Post by drgz »

localghost wrote:I overlooked this part of code because I'm used to adding individual legend entries with the \addlegendentry command right after a plot command. Never mind. I can reproduce this effect. So I suggest to contact the package maintainer.
Right after posting the second post I came to think that you're probably just used to do it in a different way; anyways, I'll try to contact the package maintainer and if I get a decent answer which solves the problem I'll update this post.

Anyways, thanks for the effort - although the problem still remains you did an effort to try, and that's appreciated.

drgz
drgz
Posts: 44
Joined: Sat Apr 18, 2009 8:40 pm

Increasing line width of legend box for PGFplots

Post by drgz »

I got an answer on my support request. Just quoting the answer in order to avoid any misunderstandings/mistakes:
ludewich @ pgfplots - sourceforge wrote: Hi,

One possible solution is to add 'cells={line width=0.4pt}' (which,
according to the pgfmanual, is the default line width).

Thus, the line becomes:
legend style={nodes=right,line width=1.5pt,cells={line width=0.4pt}}

The 'cells' style applies to the cells inside of the legend and thus
resets the outer line width.

I admit it is not the fully satisfactory solution... studying the
pgfmanual.pdf for how to change styles for matrices lead me to the
conclusion that maybe it is the only solution at hand (the legend is
actually nothing but a TikZ matrix).

I hope it helps for the moment. I fear I can't provide more (unless I
missed something about the usage of TikZ matrices).

Best regards

Christian
Post Reply