6

I would like to draw a line around given subsets of nodes in Tikz. I have five nodes in total, and two overlapping subsets (red and black) of three nodes sharing one node (cf the attached picture). The issue is that the double lines have a white interior, therefore the red line hides the black one at the overlapping node.

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}[scale=4,
    vertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},
    arc/.style={draw=blue!50,thick,->},
    arc label/.style={fill=white,font=\tiny,inner sep=1pt},
    loop arc/.style={min distance=2mm}
    ]
% Subset 1
\draw[double=none, double distance=60pt, line join=round, line cap=round, draw=black] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
% Subset 2
\draw[double=none, double distance=60pt, line join=round, line cap=round, draw=red] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\end{tikzpicture}
\end{figure}

\end{document}

I thought that the option double=none would solve the issue, but it seems that I am missing something, any ideas?

Thank you in advance for your help.

enter image description here

2
  • 1
    I don't think it's possible to have a transparent center in the "double" option... (I suppose the double line are done by drawing a second smaller white line on the main one). So you might have to draw the contour by hand. If you want to do so, you might want to use the polar coordinate (angle:radius) with the calc package and the arc function. But I hope someone will find a better solution.
    – Vinzza
    Sep 7, 2018 at 12:35
  • Yes, it is possible to draw it "manually" but it means that you need an arc plus a line segment... It feels like there should be an easier solution :-D
    – RockyRock
    Sep 7, 2018 at 14:37

2 Answers 2

5

By playing around with transparency group one can create the desired effect:

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}[scale=4,
    vertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},
    arc/.style={draw=blue!50,thick,->},
    arc label/.style={fill=white,font=\tiny,inner sep=1pt},
    loop arc/.style={min distance=2mm}
    ]

\pgfsetblendmode{multiply}    

\begin{scope}[transparency group]    
% Subset 1
\draw[double=none, double distance=60pt, line join=round, line cap=round, draw=black] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
\end{scope}

\begin{scope}[transparency group]
% Subset 2
\draw[double=none, double distance=60pt, line join=round, line cap=round, draw=red] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\end{scope}
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here


\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}[scale=4,
    vertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},
    arc/.style={draw=blue!50,thick,->},
    arc label/.style={fill=white,font=\tiny,inner sep=1pt},
    loop arc/.style={min distance=2mm}
    ]

\pgfsetblendmode{multiply}

\begin{scope}[transparency group]
\draw[line width=60pt, line join=round, line cap=round, draw=red] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\draw[line width=40pt, line join=round, line cap=round, draw=white] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\draw[line width=60pt, line join=round, line cap=round, draw=black] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
\draw[line width=40pt, line join=round, line cap=round, draw=white] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
\end{scope}

\begin{scope}[transparency group]
\draw[line width=60pt, line join=round, line cap=round, draw=black] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
\draw[line width=40pt, line join=round, line cap=round, draw=white] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
\draw[line width=60pt, line join=round, line cap=round, draw=red] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\draw[line width=40pt, line join=round, line cap=round, draw=white] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\end{scope}

\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

2
2

This is what I was trying to achieve originally, with a graph on the top layer as follows,

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{ifthen}

% Weighted graph from adjacency matrix
\newcommand{\weigthedgraphfromadj}[6][draw,->]{
    \foreach [count=\r] \row in {#3}{
        \foreach [count=\c] \cell in \row{
            \ifnum\cell>0
                \ifnum\c=\r
                    \draw[arc/.try=\cell] (#2\r) edge[loop arc, in= #4*\r -#5 -#4*#6, out= #4*\r +#5 -#4*#6] node[arc label/.try=\cell]{\cell} (#2\c);
                \else
                    \draw[arc/.try=\cell, #1] (#2\r) edge node[arc label/.try=\cell]{\cell} (#2\c);
                \fi
            \fi
        }
    }
}

\begin{document}
\begin{figure}[!htbp]
\centering
\begin{tikzpicture}[scale=4,
    vertex/.style={draw,circle,minimum size=0.75cm,inner sep=0pt},
    arc/.style={draw=blue!50,thick,->},
    arc label/.style={fill=white,font=\tiny,inner sep=1pt},
    loop arc/.style={min distance=2mm}
    ]

\pgfsetblendmode{multiply}    
\begin{scope}[transparency group]    
% Subset 1
\draw[double=none, double distance=60pt, line join=round, line cap=round, draw=black] (1,0)--(0.3090,0.9511)--(-0.8090,0.5878);
\end{scope}

\begin{scope}[transparency group]
% Subset 2
\draw[double=none, double distance=60pt, line join=round, line cap=round, draw=red] (-0.8090,0.5878)--(-0.8090,-0.5878)--(0.3090,-0.9511);
\end{scope}
\pgfsetblendmode{normal}
    \foreach [count=\i] \coord in
                        {(0.3090,0.9511),
                        (-0.8090,0.5878),
                        (-0.8090,-0.5878),
                        (0.3090,-0.9511),
                        (1,0)}
                        {
        \ifthenelse{\i<4}{\node[vertex] (p\i) at \coord {$x_{\i}$}}{\ifthenelse{\i=4}{\node[vertex] (p\i) at \coord {$u_{2}$}}{\node[vertex] (p\i) at \coord {$u_{1}$}}};
    }
    \weigthedgraphfromadj[bend left=10]{p}{{1,1,1,0,0},
                                            {24,20,24,0,0},
                                            {1,1,1,0,0},
                                            {0,0,2,0,0},
                                            {2,0,0,0,0}}{72}{30}{0}
\end{tikzpicture}
\end{figure}

\end{document}

There is a graph macro plotting graphs from some coordinates and an adjacency matrix. The sets are overlapping weighted directed subgraphs.

Hope it can be of some use for others.

Romain

enter image description here

3

You must log in to answer this question.

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