53

I am trying to draw a picture using TikZ in LaTeX. In this example, I have drawn two curved lines and a vertical line. I would like to make the lower curved line only visible to the right of the vertical line. In other words, I would like to clip the lower curved line. However, I do not want to clip the entire picture. I would still like to view the entire top curve. Is this possible in TikZ?

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=5]
\draw (.1,1.6) .. controls (.6,1.6) and (1.5,1) .. (2,1);
\draw (.1,1) .. controls (.6,1) and (1.5,.4) .. (2,.4);
\draw[dashed] (1,0) -- (1,2);
\end{tikzpicture}

\end{document}
1
  • 1
    @Tom I changed the question slightly to more clearly indicate that I didn't want to clip the entire picture, but just the one curve. Sorry for the confusion.
    – profj
    Mar 22, 2012 at 21:30

1 Answer 1

64

Yes, you can use the \clipcommand inside a scope:

\documentclass{article}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}[scale=5]

\begin{scope}
    \clip(1,0) rectangle (2,2);
    \draw (.1,1.6) .. controls (.6,1.6) and (1.5,1) .. (2,1);
\end{scope}

\draw[dashed] (1,0) -- (1,2);

\end{tikzpicture}

\end{document}

enter image description here


Only the things in the scope are clipped:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=5]
\draw (.1,1.6) .. controls (.6,1.6) and (1.5,1) .. (2,1);

\begin{scope}
    \clip (1,0) rectangle (2,2);
    \draw (.1,1) .. controls (.6,1) and (1.5,.4) .. (2,.4);
\end{scope} 

\draw[dashed] (1,0) -- (1,2);
\end{tikzpicture}

\end{document}

enter image description here

4
  • 1
    Oops let me delete mine :)
    – percusse
    Mar 22, 2012 at 21:28
  • 3
    @percusse: same idea, and also around immedeately? I know that feeling ;) Mar 22, 2012 at 21:33
  • @Tom Thanks! This is exactly what I was looking for.
    – profj
    Mar 22, 2012 at 21:33
  • To only clip in a single direction, see this answer: tex.stackexchange.com/a/149523/153678
    – Paul Wintz
    Nov 3, 2023 at 6:24

You must log in to answer this question.

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