当我回答的时候另一个问题,我意识到当该选项every matrix/.style={name=...}
添加到tikz-cd
环境中时,会出现一些虚假空间,请参阅以下 MWE:
\documentclass{article}
\usepackage{tikz-cd}
\usepackage{mwe}
\begin{document}
The difference between these commutative diagrams:
\begin{tikzcd}[execute at end picture={
\filldraw[red] (\tikzcdmatrixname-1-1) circle[radius=1pt];
\filldraw[blue] (\tikzcdmatrixname-1-2) circle[radius=1pt];
\filldraw[green] (\tikzcdmatrixname-2-1) circle[radius=1pt];
\filldraw[orange] (\tikzcdmatrixname-2-2) circle[radius=1pt];
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D \\
\end{tikzcd}%
\begin{tikzcd}[execute at end picture={
\filldraw[red] (\tikzcdmatrixname-1-1) circle[radius=1pt];
\filldraw[blue] (\tikzcdmatrixname-1-2) circle[radius=1pt];
\filldraw[green] (\tikzcdmatrixname-2-1) circle[radius=1pt];
\filldraw[orange] (\tikzcdmatrixname-2-2) circle[radius=1pt];
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D \\
\end{tikzcd}%
and the following two is only the \texttt{every matrix/.style=\{name=...\}} option, which produces some spurios spaces, as you can easily see:
\begin{tikzcd}[every matrix/.style={name=mycd},
execute at end picture={
\filldraw[red] (mycd-1-1) circle[radius=1pt];
\filldraw[blue] (mycd-1-2) circle[radius=1pt];
\filldraw[green] (mycd-2-1) circle[radius=1pt];
\filldraw[orange] (mycd-2-2) circle[radius=1pt];
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D \\
\end{tikzcd}%
\begin{tikzcd}[every matrix/.style={name=mycd},
execute at end picture={
\filldraw[red] (mycd-1-1) circle[radius=1pt];
\filldraw[blue] (mycd-1-2) circle[radius=1pt];
\filldraw[green] (mycd-2-1) circle[radius=1pt];
\filldraw[orange] (mycd-2-2) circle[radius=1pt];
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D \\
\end{tikzcd}%
Is there any \texttt{\%} missing somewhere?
\end{document}
答案1
风格every matrix
定义为
every matrix/.style={/tikz/inner sep=+0pt},
然后您完全重新定义它,从而删除了设置,我猜想会使用inner sep
的默认值。因此,您想将 添加到样式中,而不是重新定义它。(此外,您可能希望从最后一行中删除 ,这样会得到一个空行。)0.333em
every matrix/.append style
\\
输出,绘制边界矩形:
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
The difference between these commutative diagrams:
\begin{tikzcd}[execute at end picture={
\filldraw[red] (\tikzcdmatrixname-1-1) circle[radius=1pt];
\filldraw[blue] (\tikzcdmatrixname-1-2) circle[radius=1pt];
\filldraw[green] (\tikzcdmatrixname-2-1) circle[radius=1pt];
\filldraw[orange] (\tikzcdmatrixname-2-2) circle[radius=1pt];
\draw (current bounding box.south west) rectangle (current bounding box.north east);
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D
\end{tikzcd}%
\begin{tikzcd}[execute at end picture={
\filldraw[red] (\tikzcdmatrixname-1-1) circle[radius=1pt];
\filldraw[blue] (\tikzcdmatrixname-1-2) circle[radius=1pt];
\filldraw[green] (\tikzcdmatrixname-2-1) circle[radius=1pt];
\filldraw[orange] (\tikzcdmatrixname-2-2) circle[radius=1pt];
\draw (current bounding box.south west) rectangle (current bounding box.north east);
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D
\end{tikzcd}%
and the following two is only the \texttt{every matrix/.style=\{name=...\}} option, which produces some spurios spaces, as you can easily see:
\begin{tikzcd}[every matrix/.append style={name=mycd},
execute at end picture={
\filldraw[red] (mycd-1-1) circle[radius=1pt];
\filldraw[blue] (mycd-1-2) circle[radius=1pt];
\filldraw[green] (mycd-2-1) circle[radius=1pt];
\filldraw[orange] (mycd-2-2) circle[radius=1pt];
\draw (current bounding box.south west) rectangle (current bounding box.north east);
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D
\end{tikzcd}%
\begin{tikzcd}[every matrix/.append style={name=mycd},%
execute at end picture={%
\filldraw[red] (mycd-1-1) circle[radius=1pt];
\filldraw[blue] (mycd-1-2) circle[radius=1pt];
\filldraw[green] (mycd-2-1) circle[radius=1pt];
\filldraw[orange] (mycd-2-2) circle[radius=1pt];
\draw (current bounding box.south west) rectangle (current bounding box.north east);
}]
A \ar[r]\ar[d] & B \ar[d] \\
C \ar[r] & D
\end{tikzcd}%
Is there any \texttt{\%} missing somewhere?
\end{document}