具有忽略 z 顺序/填充的图案的 Tikz 节点

具有忽略 z 顺序/填充的图案的 Tikz 节点

我正在尝试绘制带有图案(即阴影)的重叠圆圈。重叠圆圈旨在隐藏底层圆圈. 通常情况下就是这样的无图案,但是一旦我添加模式,的值fill似乎就被完全忽略了。

有什么办法可以使用patterns fill? 提前致谢!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{%
    shapes.misc,    % additional shapes, such as rounded rectangles
    positioning,    % advanced positioning
    patterns,       % hatches etc
}

\begin{document}
\begin{tikzpicture}[%
    roundnode/.style={circle, draw=black, fill=yellow!20, thick, inner sep=0em, opacity=1, fill opacity=1, draw opacity=1, font=\small},
    ]
    
    \node[roundnode, minimum size=15mm] (nodeA) at (1, 0) {A};
    \node[roundnode, minimum size=15mm, fill=red!20, pattern=north west lines, pattern color=gray] (nodeB) at (2, 0) {B};
    
    \node[roundnode, minimum size=15mm] (nodeC) at (2, 1) {C};
    \node[roundnode, minimum size=15mm, pattern=north east lines, pattern color=gray] (nodeD) at (2, -1) {D};
    
\end{tikzpicture}
\end{document}

答案1

您可以使用postaction来实现所需的效果。请注意,还有patterns.meta一种可能更方便的方法来添加图案(但您仍然需要postaction或声明一个填充图案)。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{%
    shapes.misc,    % additional shapes, such as rounded rectangles
    positioning,    % advanced positioning
    patterns,       % hatches etc
}

\begin{document}
\begin{tikzpicture}[%
    roundnode/.style={circle, draw=black, fill=yellow!20, thick, inner sep=0em, opacity=1, fill opacity=1, draw opacity=1, font=\small},
    ]
    
    \node[roundnode, minimum size=15mm] (nodeA) at (1, 0) {A};
    \node[roundnode, minimum size=15mm, fill=red!20, 
        postaction={pattern=north west lines, pattern color=gray}] (nodeB) at (2, 0) {B};
    
    \node[roundnode, minimum size=15mm] (nodeC) at (2, 1) {C};
    \node[roundnode, minimum size=15mm, 
        postaction={pattern=north east lines, pattern color=gray}] (nodeD) at (2, -1) {D};
    
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容