可能我的标题不太有用。我的问题是我尝试使用以下代码在某些顶点上“绘制”超边:
\usepackage{tikz}
\tikzstyle{vertex} = [fill, shape=circle, opacity=1, node distance=80pt]
\tikzstyle{hyperedge} = [fill, opacity=1, cap=round, join=round, line width=60pt]
\tikzstyle{elabel} = [fill, shape=circle, node distance=30pt]
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{tikzpicture}
\node[vertex,label=above left:$v_1$] (v1) {};
\node[vertex,right of=v1,label=above right:$v_2$] (v2) {};
\node[vertex,below of=v1,label=below left:$v_3$] (v3) {};
\node[vertex,right of=v3,label=below right:$v_4$] (v4) {};
\begin{pgfonlayer}{background}
\draw[hyperedge, color=yellow] (v1.center)--(v2.center)--(v3.center)--cycle;
\draw[hyperedge, color=pink, line width=45pt] (v2.center)--(v3.center)--(v4.center)--cycle;
\end{pgfonlayer}
\node[elabel,color=yellow,label=right:$C_1$] (e1) at (-3,0) {};
\node[elabel,below of=e1,color=pink,label=right:$C_2$] (e2) {};
\end{tikzpicture}
\end{document}
这将产生以下内容:
效果还不错,但是交叉点不太明显。如果我将超边的不透明度设置为 0.5:
\tikzstyle{hyperedge} = [fill, opacity=0.5, cap=round, join=round, line width=60pt]
我得到:
这里的交叉点更加明显,但由于“填充”和循环的“线条”也相交,受影响的部分变得更加不透明(?)。有没有办法解决这种情况?也许只在循环的一侧绘制线条,避免与填充相交,但这可能吗?
答案1
我认为正确的解决方案是这样的。我在手册中找到了它:
从“超边”样式中移除不透明度:
\tikzstyle{hyperedge} = [fill, cap=round, join=round, line width=60pt]
将每条边放入其自己的透明度组中:
\begin{scope}[transparency group, opacity=0.5]
\draw[hyperedge, color=yellow] (v1.center)--(v2.center)--(v3.center)--cycle;
\end{scope}
\begin{scope}[transparency group, opacity=0.5]
\draw[hyperedge, color=pink, line width=45pt] (v2.center)--(v3.center)--(v4.center)--cycle;
\end{scope}
谢谢大家的答案!
答案2
肮脏的黑客:
如果特定形状的线条稍微宽一些,则无需担心任何填充颜色,因为线条会填充整个形状:
\documentclass{standalone}
\usepackage{tikz}
\tikzset{
vertex/.style={fill, shape=circle, opacity=1, node distance=80pt},
hyperedgeline/.style={opacity=0.5, cap=round, join=round,line width=60pt},
elabel/.style={fill, shape=circle, node distance=30pt}
}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{tikzpicture}
\node[vertex,label=above left:$v_1$] (v1) {};
\node[vertex,right of=v1,label=above right:$v_2$] (v2) {};
\node[vertex,below of=v1,label=below left:$v_3$] (v3) {};
\node[vertex,right of=v3,label=below right:$v_4$] (v4) {};
\begin{pgfonlayer}{background}
\draw[hyperedgeline, color=yellow] (v1.center)--(v2.center)--(v3.center)--cycle;
\draw[hyperedgeline, color=pink, line width=47pt] (v2.center)--(v3.center)--(v4.center)--cycle;
\end{pgfonlayer}
\node[elabel,color=yellow,label=right:$C_1$] (e1) at (-3,0) {};
\node[elabel,below of=e1,color=pink,label=right:$C_2$] (e2) {};
\end{tikzpicture}
\end{document}
答案3
使用fill opacity
。
\documentclass{article}
\usepackage{tikz}
\tikzstyle{vertex} = [fill, shape=circle, opacity=1, node distance=80pt]
\tikzstyle{hyperedge} = [opacity=0.5,fill opacity=1, cap=round, join=round, line width=60pt]
\tikzstyle{elabel} = [fill, shape=circle, node distance=30pt]
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{document}
\begin{tikzpicture}
\node[vertex,label=above left:$v_1$] (v1) {};
\node[vertex,right of=v1,label=above right:$v_2$] (v2) {};
\node[vertex,below of=v1,label=below left:$v_3$] (v3) {};
\node[vertex,right of=v3,label=below right:$v_4$] (v4) {};
\begin{pgfonlayer}{background}
\draw[hyperedge, color=yellow] (v1.center)--(v2.center)--(v3.center)--cycle;
\draw[hyperedge, color=pink, line width=45pt] (v2.center)--(v3.center)--(v4.center)--cycle;
\end{pgfonlayer}
\node[elabel,color=yellow,label=right:$C_1$] (e1) at (-3,0) {};
\node[elabel,below of=e1,color=pink,label=right:$C_2$] (e2) {};
\end{tikzpicture}
\end{document}