39

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
    @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 '12 at 21:30
48

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

| improve this answer | |
  • 1
    Oops let me delete mine :) – percusse Mar 22 '12 at 21:28
  • 3
    @percusse: same idea, and also around immedeately? I know that feeling ;) – Tom Bombadil Mar 22 '12 at 21:33
  • @Tom Thanks! This is exactly what I was looking for. – profj Mar 22 '12 at 21:33

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.