32

Is there some macro that will tell me what the default PGF line width is? I have tried creating my own macro by cloning \pgflinewidth before it has been modified, i.e.

\let\defaultlinewidth\pgflinewidth

but \defaultlinewidth seems to be affected by \pgfsetlinewidth anyway, and change to whatever \pgflinewidth is. So, the problem is that after I have called \pgfsetlinewidth, I don't know what the default pgf line width is anymore. Is there some way to get around this?

lockstep
  • 250,273

3 Answers3

33

You can always query PGF directly:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\foreach \width [count=\yi] in {ultra thin,very thin,thin,semithick, thick, very thick, ultra thick}
  \node[\width] at (0,-0.5*\yi) {The value with the \texttt{\width} option is \the\pgflinewidth};
\end{tikzpicture}

\end{document}

enter image description here

In a similar way, you can define a command to keep the default value:

\documentclass{article}
\usepackage{tikz}

\newcommand\defvalue{%
  \tikz[baseline=-0.5ex]\node[line width=\pgflinewidth] {The default value is \the\pgflinewidth};}

\begin{document}

\begin{tikzpicture}
\pgfsetlinewidth{3pt}
\draw (0,3ex) -- (1,3ex);
\node at (6,3ex) {The current value is \the\pgflinewidth. \defvalue};
\pgfsetlinewidth{3mm}
\draw (0,-1cm) -- (1,-1cm);
\node at (6,-1cm) {The current value is \the\pgflinewidth. \defvalue};
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
23

If you mean the standard line width, it's 0.4 pt or the setting thin.

\tikzstyle{ultra thin}=              [line width=0.1pt]
\tikzstyle{very thin}=               [line width=0.2pt]
\tikzstyle{thin}=                    [line width=0.4pt]
\tikzstyle{semithick}=               [line width=0.6pt]
\tikzstyle{thick}=                   [line width=0.8pt]
\tikzstyle{very thick}=              [line width=1.2pt]
\tikzstyle{ultra thick}=             [line width=1.6pt]
percusse
  • 157,807
  • That might be correct, but do you have any source for that? It would also feel better if I could extract it during compilation somehow and not having to trust information from the web. – StrawberryFieldsForever Aug 04 '12 at 00:49
  • 4
    @StrawberryFieldsForever Why do you ask online then? (search tikz.code.tex for these settings) – percusse Aug 04 '12 at 00:55
  • 3
    @StrawberryFieldsForever: You can read the manual first. pgfmanual will tell you the values. – Leo Liu Aug 04 '12 at 02:00
  • @StrawberryFieldsForever: as @LeoLiu suggested, by looking in the manual for line width you would have found 15.3.1 Graphic Parameters: Line Width, Line Cap, and Line Join (pgfmanual version October 25, 2010). – Claudio Fiandrino Aug 04 '12 at 06:51
  • @percusse, @Leo, @Claudio: Thanks. Chapter 15.3.1 did contain the information (and the source) I was looking for, which of course told me what percusse had already said. I has been searching for pgflinewidth and thought that would give me the answer I wanted. – StrawberryFieldsForever Aug 04 '12 at 09:48
  • @percusse, @Leo, @Claudio: I was also already a bit sceptical because I had tried to google the default PGF linewidth and I had found answers like 1pt (which on the other hand didn't make any sense to me because it looked terrible when I was trying to use it). – StrawberryFieldsForever Aug 04 '12 at 10:02
  • @StrawberryFieldsForever As pgfmanual says (p.156, pgfmanual v2.10): "line width (no default, initially 0.4pt)" – Paul Gaborit Aug 04 '12 at 16:21
  • @PolGab: Yes, you're right, it should be "initial value". I just stated my question as asking for the "default PGF line width" and felt I couldn't abruptly switch to "initial value", so I stuck to that for a while. – StrawberryFieldsForever Aug 04 '12 at 21:09
17

\pgflinewidth is a length. So you can use \setlength to copy its current value:

\documentclass{standalone}
\usepackage{tikz}
\newlength{\defaultpgflinewidth}
\setlength{\defaultpgflinewidth}{\pgflinewidth}
\begin{document}
\begin{tikzpicture}[line width=1mm]
  \draw circle [radius=1cm];
  \draw[line width=\defaultpgflinewidth] (-1cm,-1cm) rectangle (1cm,1cm);
\end{tikzpicture}
\end{document}

enter image description here

Edit (suggestion from Christian Feuersänger)

You can also use \edef to make a copy of the current representation of this length.

 \edef\defaultpgflinewidth{\the\pgflinewidth}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
  • Nice! Just what I was looking for. :) So it is \setlength you have to use to copy a length, do you know why \let doesn't work? – StrawberryFieldsForever Aug 04 '12 at 15:17
  • 2
    \let will create another name for the same dimen register. It is like creating a new pointer to the same object. But you want a copy, not a reference - in that case, you can use the \setlength solution (as here, although this might waste a TeX register) or you use \edef\defaultpgflinewidth{\the\pgflinewidth} which will also store a copy (but into a cheap macro). – Christian Feuersänger Aug 04 '12 at 19:34
  • @ChristianFeuersänger Good suggestion. I will edit my answer to add it. – Paul Gaborit Aug 04 '12 at 21:52
  • @Paul: Can you also use the \edef solution if you would want to define a length that is a factor a length, for example 1.5\pgflinewidth? I have tried \edef\mylength{1.5\the\pgflinewidth} and \edef\mylength{\the{1.5\pgflinewidth}} but both of those give me an error. \setlength still works fine, though. – StrawberryFieldsForever Aug 13 '12 at 13:37
  • Here's a link to a different question - but the answer is related, as it explains the mechanisms behind \pgflinewidth: http://tex.stackexchange.com/questions/185163/reading-and-effect-of-default-tikz-pgf-keys/185170#185170 – sdaau Jun 18 '14 at 01:41