3

On the left I have created two nodes (Zero Node in blue and One Node in gray) and would like to draw over the existing path from A-B-C-D (including the notches).

On the right is my attempt drawn in red, which isn't quite right.

How can I do a better job at this and is there an easier way to do this?

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\tikzset{Node Style Gray/.style={
    rounded corners, 
    minimum width=3cm,
    minimum height=2cm,
    draw=gray,
    ultra thick,
    inner sep=0pt,
    opacity=0.5, 
}}
\tikzset{Node Style Blue/.style={
    rounded corners, 
    minimum width=3cm,
    minimum height=2cm,
    draw=blue,
    thick,
    inner sep=0pt,
}}

\begin{document}
\begin{tikzpicture}
\node (Zero) at (0,0) {0};
\node (One)  at (0,3) {1};
\node [Node Style Blue, fit={(Zero)           }] (Zero Node) {};
\node [Node Style Gray, fit={(Zero Node) (One)}] (One Node)  {};
    
\node [right] at (Zero Node.north east) {A};
\node [left]  at (Zero Node.north west) {B};
\node [left]  at (One Node.north west)  {C};
\node [right] at (One Node.north east)  {D};

%% ------------------------------------------- My attempt
\draw [rounded corners, red, ultra thick] 
       (One Node.north east)
    -- (One Node.north west)
    -- ([yshift=-1.0ex]One Node.north west |- Zero Node.north west)
    -- ++(0,1.0ex)
    -| ([yshift=-1.0ex]Zero Node.north east -| One Node.north east)
    --cycle
    ;
\end{tikzpicture}
\end{document}
3

I think you simply neglect the widths of the lines. Since the gray and blue lines come with different widths, I cannot provide a perfect overlap with simple rounded corners. Otherwise just subtracting the line widths seems to work. To this end, I introduce a fake fit node with negative inner sep, whose value is determined by the line widths of the fitted node and the one drawn afterwards (red), of course divided by two. UPDATE: In a second picture, I add a fit of the lower two arcs with elliptic arcs, where the "ellipticity" is governed by a calculable difference of line widths.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\tikzset{Node Style Gray/.style={
    rounded corners, 
    minimum width=3cm,
    minimum height=2cm,
    draw=gray,
    ultra thick,
    inner sep=0pt,
    opacity=0.5, 
}}
\tikzset{Node Style Blue/.style={
    rounded corners, 
    minimum width=3cm,
    minimum height=2cm,
    draw=blue,
    thick,
    inner sep=0pt,
}}
\tikzset{fake fit/.style={draw=none,inner sep=-1pt,fit=#1}}
% 1pt = 0.5 * (0.4pt+1.6pt), 
% where 0.4pt is the ordinary line width and 1.6pt is ultra thick line width

\begin{document}
\begin{tikzpicture}
\node (Zero) at (0,0) {0};
\node (One)  at (0,3) {1};
\node [Node Style Blue, fit={(Zero)           }] (Zero Node) {};
\node [Node Style Gray, fit={(Zero Node) (One)}] (One Node)  {};

\node (A) [right] at (Zero Node.north east) {A};
\node (B) [left]  at (Zero Node.north west) {B};
\node (C) [left]  at (One Node.north west)  {C};
\node (D) [right] at (One Node.north east)  {D};


\node[fake fit=(One Node)] (Fake One Node) {};
%% ------------------------------------------- My attempt
\draw [rounded corners, red, ultra thick,opacity=0.5] {\pgfextra{\typeout{\the\pgflinewidth}}}
       (Fake One Node.north east)
    -- (Fake One Node.north west)
    -- ([yshift=-1.0ex]Fake One Node.north west |- Zero Node.north west)
    -- ++(0,1.0ex)
    -| ([yshift=-1.0ex]Zero Node.north east -| Fake One Node.north east)
    --cycle
    ;
\end{tikzpicture}~%
\begin{tikzpicture}
\node (Zero) at (0,0) {0};
\node (One)  at (0,3) {1};
\node [Node Style Blue, fit={(Zero)           }] (Zero Node) {};
\node [Node Style Gray, fit={(Zero Node) (One)}] (One Node)  {};

\node (A) [right] at (Zero Node.north east) {A};
\node (B) [left]  at (Zero Node.north west) {B};
\node (C) [left]  at (One Node.north west)  {C};
\node (D) [right] at (One Node.north east)  {D};


\node[fake fit=(One Node)] (Fake One Node) {};
%% ------------------------------------------- My attempt
\pgfmathsetmacro{\arcX}{1.0ex+0.5*(1.6pt-0.4pt)}
\typeout{\arcX}
\draw [red, ultra thick,opacity=0.5] 
       (Fake One Node.north east)
     -- (Fake One Node.north west)
    -- 
    ([yshift=-1.0ex]Fake One Node.north west |- Zero Node.north west)
    arc(180:90:\arcX*1pt and 1.0ex)
    -- ([xshift=-\arcX*1pt]Zero Node.north east -| Fake One Node.north east)
    arc(90:0:\arcX*1pt and 1.0ex)
     --cycle
    ;
\end{tikzpicture}
\end{document}

enter image description here

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.