I am trying to superpose 2 rectangles; one blue, one red, and have the intersection area with a mix of blue and red. I have problems with the borders though.
-
I am not getting the thickness of the borders correctly where rectangles intersect
-
when using rounded corners, I don't see how to nicely get 2 angles rounded (south west and north east) and 2 not.
Any idea?
Here is my MWE:
\documentclass{article}
\usepackage{tikz}
\tikzset{
box1/.style={draw=black, thick, rectangle,rounded corners, minimum height=4cm, minimum width=4cm},
box2/.style={draw=black, thick, rectangle, minimum height=4cm, minimum width=4cm},
}
\begin{document}
\begin{tikzpicture}
\node[box1, fill=red!10] (c2) at (0,0) {};
\node[box1, fill=blue!10] (c1) at (2,2) {};
\begin{scope}
\clip (0,0) rectangle (4,4);
\clip (-2,-2) rectangle (2,2);
\fill[color=blue!50!red!10, rounded corners, draw=black, thick] (2,2) rectangle (0,0);
\end{scope}
\node[box2, fill=red!10] (c2) at (8,0) {};
\node[box2, fill=blue!10] (c1) at (10,2) {};
\begin{scope}
\clip (8,0) rectangle (12,4);
\clip (6,-2) rectangle (10,2);
\fill[color=blue!50!red!10, draw=black, thick] (10,2) rectangle (8,0);
\end{scope}
\end{tikzpicture}
\end{document}
Best Answer
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 ofopacity
to affect only the filling and not the border (draw opacity
).