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.

Below is my example. I'd like to use a global style for all my tikz pictures to set up the line width. It is working well until I use a clip. I guess that it is not possible to pass some style option to clip. The code below gives the error msg

Package tikz Error: Extra options not allowed for clipping path command. \clip (2,0) circle (2cm);

Here is the MWE.

\documentclass{article}
\usepackage{tikz}
\tikzset{every path/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}

Any help?

share|improve this question
1  
See also tex.stackexchange.com/questions/4907/… –  Andrew Stacey Dec 27 '12 at 21:53
add comment

2 Answers

up vote 6 down vote accepted

Here are three solutions.

1) If you necessarily need every path/.style, choose this excellent answer from Matthew Leingang (but the TeX group around \clip prevents the propagation of the bounding box):

\documentclass{article}
\usepackage{tikz}

\tikzset{every path/.style={draw=blue,line width=2pt}}
\begin{document}
\begin{tikzpicture}
  {
    \tikzset{every path/.style={}}
    \clip (2,0) circle (2cm);
  }
  \draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}

2) Most of the time, you can avoid to use every path/.style. Here, you can use every picture/.style instead of every path/.style:

\documentclass{article}
\usepackage{tikz}
\tikzset{every picture/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}

3) The third solution redefines the clip option :

\documentclass{article}
\usepackage{tikz}

\makeatletter
\tikzset{clip/.code={%
    \let\tikz@mode=\pgfutil@empty%
    \let\tikz@preactions=\pgfutil@empty%
    \let\tikz@postactions=\pgfutil@empty%
    \let\tikz@options=\pgfutil@empty%
    \tikz@addmode{\tikz@mode@cliptrue}%
  },
}
\makeatother

\tikzset{every path/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
  \clip (2,0) circle (2cm);
  \draw (0,0) circle (3cm);
\end{tikzpicture}
\end{document}
share|improve this answer
    
Well, if you’re proposing the second solution, do \tikzset{clip/.code={\tikz@addmode{\tikz@mode@cliptrue}\let\tikz@options=\pgfut‌​il@empty}} and you can use the original \path[clip] and \clip. –  Qrrbrbirlbel Dec 26 '12 at 18:44
    
@Qrrbrbirlbel Thanks for your suggestion: I edited my answer. –  Paul Gaborit Dec 26 '12 at 18:58
    
Of these three, Matthew's is the most reliable and robust. It really should be the first version given. –  Andrew Stacey Dec 26 '12 at 23:13
    
@AndrewStacey The first solution is simpler: every picture can replace every path in the majority of cases! –  Paul Gaborit Dec 26 '12 at 23:20
    
Disagree. In simple cases, maybe, but it's not difficult to come up with examples where the behaviour is radically different. every scope comes in between, for example. –  Andrew Stacey Dec 26 '12 at 23:32
show 4 more comments

This is a crude method. Instead of changing the path style, you can define a my path and use it.

\documentclass{article}
\usepackage{tikz}
\tikzset{my path/.style={line width=2pt}}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\draw [my path] (0,0) circle (3cm);
\end{tikzpicture}
\end{document}

enter image description here

Or define tikzset after clip (if needed put it inside a scope):

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\clip (2,0) circle (2cm);
\begin{scope}
\tikzset{every path/.style={line width=2pt}}
\draw  (0,0) circle (3cm);
\end{scope}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks for your help. But with you suggestion I would have to use the my style on every picture. I'd like to set up global line width to change on the whole document. –  Sigur Dec 26 '12 at 12:29
1  
@Sigur Unfortunately yes. But second option is somewhat less brutal. For using it globally, one has to patch the \clip command. Let us wait for tikz gurus. :-) –  Harish Kumar Dec 26 '12 at 12:41
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.