我有下图:
\begin{tikzcd}[ampersand replacement=\&]
x \arrow[rr] \arrow[dr] \& \& y \arrow[dl] \\
\& z \& \\
\end{tikzcd}
我想使用:
\fill[pattern=north east lines, pattern color=blue],
用该模式填充它。正确的做法是什么?每次我尝试这样做时都会出错。
答案1
我觉得它看起来很丑,但是,如果这是你想要的......
您可以使用fit
库和execute at end picture
选项:
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{fit, patterns}
\begin{document}
\[
\begin{tikzcd}[ampersand replacement=\&, execute at end picture={
\node[rectangle, draw, blue,
pattern=north east lines, pattern color=blue,
fit={(tikz@f@1-1-1) (tikz@f@1-1-3) (tikz@f@1-2-2)}
]
{};
}
]
x \arrow[rr] \arrow[dr] \& \& y \arrow[dl] \\
\& z \& \\
\end{tikzcd}
\]
\end{document}
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{fit, patterns, backgrounds}
\begin{document}
\[
\begin{tikzcd}[ampersand replacement=\&, execute at end picture={
\begin{scope}[on background layer]
\node[rectangle, draw, blue,
pattern=north east lines, pattern color=blue,
fit={(tikz@f@1-1-1) (tikz@f@1-1-3) (tikz@f@1-2-2)}
]
{};
\end{scope}}]
x \arrow[rr] \arrow[dr] \& \& y \arrow[dl] \\
\& z \& \\
\end{tikzcd}
\]
\end{document}
注意:这个答案的原始版本已经使用overlay
但不需要,并导致与文本垂直覆盖:
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{fit, patterns}
\usepackage{mwe}
\begin{document}
\blindtext
\[
\begin{tikzcd}[remember picture, overlay, ampersand replacement=\&]
x \arrow[rr] \arrow[dr] \& \& y \arrow[dl] \\
\& z \& \\
\end{tikzcd}
\tikz[remember picture, overlay]{
\node[rectangle, draw, blue,
pattern=north east lines, pattern color=blue,
fit={(tikz@f@1-1-1) (tikz@f@1-1-3) (tikz@f@1-2-2)}
]
{};
}
\]
\blindtext
\end{document}
答案2
我可能会想关闭您在第一个问题中提到的关于此问题的重复问题: tikz-cd:交换立方体的阴影面
这与 Gonzalo 答案的最后一部分描述的基本上相同,但是使用您的\fill
命令。
\documentclass[border=5mm]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{patterns,backgrounds}
\begin{document}
\begin{tikzcd}[
ampersand replacement=\&,
execute at end picture={
\scoped[on background layer]
\fill[pattern=north east lines, pattern color=blue] (a.center) -- (b.center) -- (c.center) -- cycle;
}]
|[alias=a]|x \arrow[rr] \arrow[dr] \& \& |[alias=b]|y \arrow[dl] \\
\& |[alias=c]|z \&
\end{tikzcd}
\end{document}
答案3
作为第一个解决方案的补充CarLaTeX 答案. 细微的变化有:
- 具有图案的节点的样式由以下定义
\tikzset
- 对于模式使用的
pattern.meta
包, - 定义为矩阵名称
\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{fit,
patterns.meta,
shapes.geometric}
\tikzset{
F/.style = {draw=blue, inner ysep=0pt, fit=#1,
postaction={pattern={Lines[angle=45,distance={2pt},
line width=0.25pt]},
pattern color=blue!50, semitransparent} }
}
\usepackage{lipsum}
\begin{document}
\lipsum[65]
\[
\begin{tikzcd}[
every matrix/.append style = {name=m},
execute at end picture = {
\node[F = (m-1-1) (m-1-3) (m-2-2) ] {};
}% end of execute at end picture
]
x \ar[rr] \ar[dr] & & y \ar[dl] \\
& z &
\end{tikzcd}
\]
\lipsum[66]
\end{document}