The problem is that you \clip
a part of the borders. Take a look at the following image. Figure a shows a black border, where the path of the border is shown in red. If you clip along the path you’ll get figure b showing that that the outer half of your black border is missing/clipped.
Possible solution
You could use transparency to overlay the two colors instead of clipping. Just set the colors with 100 percent and then set the opacity to the value you wan’t the colors to have. 10 percent means a value of 0.1. In the intersecting part the colors are mixed automatically and no clipping is needed. I used fill opacity
instead of opacity
to affect only the filling and not the border (draw opacity
).
\documentclass{article}
\usepackage{tikz}
\tikzset{
box1/.style={%
draw=black, thick,
rectangle,
rounded corners,
minimum height=4cm,
minimum width=4cm
},
}
\begin{document}
\begin{tikzpicture}
\node[box1, fill=red, fill opacity=0.1] (c2) at (0,0) {};
\node[box1, fill=blue, fill opacity=0.1] (c1) at (2,2) {};
\end{tikzpicture}
\end{document}
I think your approach was too complicated. You can simply use paths to clip things in TikZ. I'll show it through some examples, but also you can find the complete code at the end of the answer.
If you want to use only some part of an image, then include the image in a node you want to clip inside the tikzpicture, and draw the clipping path before it. When drawind the clipping path you can use the rounded corners
option before any coordinate to change the corner of it. (You can omit the draw lines simply by using path
instead of draw
.)
\begin{tikzpicture}
\draw[clip] (2cm, 0.5cm)
[rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
If you want to cut out a part from the image first you have to specify the width and height of the tikzpicture, and make sure it is the same as the included image's width and height. Then when you draw the clipping path first include the whole image in it, then continue the same path with your desired cutout. You can use the rounded corners
option in both the “bounding path” and in the cutout.
\begin{tikzpicture}[x=6cm, y=3cm]
\path[clip] [rounded corners=10pt] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
You can find the shown and more examples in the complete code below. (You can download the image I used in the example here.)
\documentclass[a4paper, 11pt]{article}
\usepackage[a4paper,
tmargin=2cm,%
rmargin=2cm,%
bmargin=2cm,%
lmargin=2cm,
vscale=1,%
hscale=1]{geometry}
\usepackage{tikz}
% only used for the example
\newlength{\skiplength}
\setlength{\skiplength}{1cm}
\setlength{\parskip}{\skiplength}
\setlength{\parindent}{0pt}
\begin{document}
\includegraphics[width=6cm, height=3cm]{clip.png}
\begin{tikzpicture}
\draw (2cm, 0.5cm)
[rounded corners=5pt] -- (3cm, 2.5cm)
[rounded corners=20pt] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}
\draw[clip] (2cm, 0.5cm)
[rounded corners=5pt] -- (3cm, 2.5cm)
[rounded corners=20pt] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}
\path[clip] (2cm, 0.5cm)
[rounded corners=5pt] -- (3cm, 2.5cm)
[rounded corners=20pt] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}[x=6cm, y=3cm]
\draw[clip] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (3cm, 2.5cm)
[rounded corners=20pt] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\begin{tikzpicture}[x=6cm, y=3cm]
\path[clip] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (3cm, 2.5cm)
[rounded corners=20pt] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}[x=6cm, y=3cm]
\path[clip] (0, 0) -- (1, 0) [rounded corners=0.5cm] -- (1, 1) [sharp corners] -- (0, 1) [rounded corners=2cm] -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (3cm, 2.5cm)
[rounded corners=20pt] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\begin{tikzpicture}
\draw (2cm, 0.5cm)
[rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}
\draw[clip] (2cm, 0.5cm)
[rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}
\path[clip] (2cm, 0.5cm)
[rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}[x=6cm, y=3cm]
\draw[clip] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\begin{tikzpicture}[x=6cm, y=3cm]
\path[clip] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\hspace{\skiplength}
\begin{tikzpicture}[x=6cm, y=3cm]
\path[clip] [rounded corners=10pt] (0, 0) -- (1, 0) -- (1, 1) -- (0, 1) -- cycle
(2cm, 0.5cm) [rounded corners=5pt] -- (2cm, 2.5cm)
[rounded corners=10pt] -- (4cm, 2.5cm)
[rounded corners=0.5cm] -- (4cm, 0.5cm)
[sharp corners] -- cycle;
\node[anchor=south west,%
inner sep=0,%
outer sep=0pt] (image) at (0, 0) {\includegraphics[width=6cm, height=3cm]{clip.png}};
\end{tikzpicture}
\end{document}
Best Answer
Thank you for your suggestions! I liked the method proposed in the answer Torbjørn T. linked to the most, so I'm answering here myself.
Code:
Output: