我想在 Tikz 中围绕给定的节点子集画一条线。我总共有五个节点,三个节点的两个重叠子集(红色和黑色)共享一个节点(参见附图)。问题是双线内部是白色的,因此红线在重叠节点处隐藏了黑线。
\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}
我以为这个选项double=none
可以解决这个问题,但似乎我遗漏了一些东西,有什么想法吗?
预先感谢您的帮助。
答案1
通过调整透明度组可以创造出所需的效果:
\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}
\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}
答案2
这是我最初想要实现的目标,顶层的图表如下,
\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}
有一个图形宏,它根据一些坐标和邻接矩阵绘制图形。这些集合是重叠的加权有向子图。
希望它能够对其他人有所帮助。
罗曼