12

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?

1

2 Answers 2

10

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}
9
  • Well, if you’re proposing the second solution, do \tikzset{clip/.code={\tikz@addmode{\tikz@mode@cliptrue}\let\tikz@options=\pgfutil@empty}} and you can use the original \path[clip] and \clip. Dec 26, 2012 at 18:44
  • @Qrrbrbirlbel Thanks for your suggestion: I edited my answer. Dec 26, 2012 at 18:58
  • Of these three, Matthew's is the most reliable and robust. It really should be the first version given. Dec 26, 2012 at 23:13
  • @AndrewStacey The first solution is simpler: every picture can replace every path in the majority of cases! Dec 26, 2012 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. Dec 26, 2012 at 23:32
5

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}
2
  • 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, 2012 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. :-)
    – user11232
    Dec 26, 2012 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .