每个 matrix/.style={name=...} 选项都会产生虚假空格

每个 matrix/.style={name=...} 选项都会产生虚假空格

当我回答的时候另一个问题,我意识到当该选项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.333emevery 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}

相关内容