4

Title explains it all really, I want to clip a picture using an exiting .pic that I have already defined, as I plan on using this clip shape many times over.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\makeatletter
\tikzset{%
         clipshape/.pic={\clip (-1,-1) rectangle (1, 1);} %just a rectangle here, but typically a more complex shape.
}%
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{scope}
    \pic {clipshape};
    \fill (0,0) circle (1.1);
\end{scope}
\end{tikzpicture}
\end{document}

Obviously the intended end result of this would be a black circle with the sides partially cut off. The MWE does compile but the clip does not occur. Am I going the right way with using pics or do I have to do something more complicated?

3

Here are two examples : one using path picture, the other a standard clip.

\documentclass[border=7pt]{standalone}
\usepackage{tikz}

\tikzset{
  clipshape 1/.pic={\path[path picture={#1}] (-1,-1) rectangle (1, 1);},
  clipshape 2/.pic={\clip (-1,-1) rectangle (1, 1);#1}
}

\begin{document}
  \begin{tikzpicture}
      \pic at (0,0) {clipshape 1={\fill[green] (0,0) circle (1.1);}};
      \pic at (3,0) {clipshape 2={\fill[red] (0,0) circle (1.1);}};
  \end{tikzpicture}
\end{document}

enter image description here

4

A simple macro definition will do:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\newcommand*{\clipshape}{
  (-1, -1) rectangle (1, 1)
}
\begin{document}
\begin{tikzpicture}
\begin{scope}
    \clip \clipshape;
    \fill (0,0) circle (1.1);
\end{scope}
\end{tikzpicture}
\end{document}

Result

The macro can then be reused, combined with other path elements and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.