我有一定的 Ti钾我想反复使用 Z 样式(因此我想将其用作范围)。也就是说,我希望曲线的颜色为红色,带有白色边框(当曲线相互交叉时产生“交叉”效果),并且我希望文本的颜色也为红色。目前我正在使用效果double
来实现这一点,如下所示:
\tikzset{curveinscope/.style={
every path/.style={
draw=white, double distance=1pt, line width=2pt, double=red, color=red}
}
}
然而,这与double
效果相冲突:将color=red
文本颜色设置为红色会将第一行的绘图颜色double
也设置为红色,这会破坏效果(它需要是白色)。
我怎样才能解决这个问题?
答案1
text=red
您应该使用而不是来设置颜色color=red
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{curveinscope/.style={every path/.style={draw=white, double distance=1pt, line width=2pt, double=red, text=red}}}
\begin{scope}[curveinscope]
\node at (1,0) {X};
\draw (0,0) -- (2,2);
\draw (2,1) -- (0,1);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
将路径特定选项与节点特定选项分开。将节点特定选项放在every node/.style
:
\documentclass{standalone}
\usepackage{tikz}
\tikzset{curve in scope/.style={
every path/.style={
draw=white,
double distance=1pt,
line width=2pt,
double=red,
},
every node/.style={
color=red
}
},
curve in scope with bad colours/.style={
every path/.style={
draw=white,
double distance=1pt,
line width=2pt,
double=red,
color=red
}
}
}
\begin{document}
\begin{tikzpicture}
\begin{scope}[curve in scope]
\path (0,0) -- node[auto] {hello world} (3,0);
\end{scope}
\begin{scope}[curve in scope with bad colours,yshift=-1cm]
\path (0,0) -- node[auto] {hello world} (3,0);
\end{scope}
\end{tikzpicture}
\end{document}
结果: