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.

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?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

\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}
share|improve this answer
    
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 4 '12 at 15:17
1  
\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 4 '12 at 19:34
    
@ChristianFeuersänger Good suggestion. I will edit my answer to add it. –  Paul Gaborit Aug 4 '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: tex.stackexchange.com/questions/185163/… –  sdaau Jun 18 at 1:41

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

share|improve this answer
    
This is nice, but I don't understand how it could tell me the default PGF line width? –  StrawberryFieldsForever Aug 4 '12 at 9:58
    
@StrawberryFieldsForever I've updated my answer showing one possibility. –  Gonzalo Medina Aug 4 '12 at 15:02
    
Your method gives seven different values, and I still don't know why the default line width would be any of these. –  StrawberryFieldsForever Aug 4 '12 at 15:12
    
Okay, I didn't see that you had updated your answer. I guess it is the \the command that makes the wonder here. I found this thread about the command here; it seems to be the key to what I was trying to do before. I guess what it does, in short, is to extracts the value of what comes next, expressed as a physical or unitless quantity? Thank you very much anyway. –  StrawberryFieldsForever Aug 4 '12 at 16:36
    
@StrawberryFieldsForever Yes; \the applied to a length expands to the length value (with the unit given in pt). –  Gonzalo Medina Aug 4 '12 at 16:46

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]
share|improve this answer
    
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 4 '12 at 0:49
2  
@StrawberryFieldsForever Why do you ask online then? (search tikz.code.tex for these settings) –  percusse Aug 4 '12 at 0:55
3  
@StrawberryFieldsForever: You can read the manual first. pgfmanual will tell you the values. –  Leo Liu Aug 4 '12 at 2: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 4 '12 at 6: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 4 '12 at 9:48

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.