在交换图上添加方框文字

在交换图上添加方框文字

我正在尝试绘制这个交换图(来源:James Munkres 的《代数拓扑元素》)。我知道如何使用 tikzcd 绘制不带方框的图。有人能帮我如何在 tikzcd 图上添加这些方框吗?

答案1

我们可以将盒子放在中间,作为“近端”的标签,但要稍微降低一点,深度要小一些。对于上面的盒子,我使用\overset,但为了安全起见,将盒子的宽度设为零。

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}

\newcommand{\sboxed}[1]{%
  \,\raisebox{-1ex}[\height][0pt]{\fbox{$\scriptstyle\mathstrut#1$}}%
}
\newcommand{\uboxed}[1]{%
  \makebox[0pt]{\fbox{$\scriptstyle\mathstrut#1$}}%
}

\begin{document}

\begin{tikzcd}[row sep=huge,column sep=large]
0 \arrow[r] &
C_{p+1} \arrow[r,"\phi"] \arrow[d,"\partial_C"',"\sboxed{c_p}" near end] &
\overset{\uboxed{d_{p+1}}}{D_{p+1}}
  \arrow[r,"\psi"] \arrow[d,"\partial_D"',"\sboxed{d_p}" near end] &
\overset{\uboxed{e_{p+1}}}{E_{p+1}}
  \arrow[r] \arrow[d,"\partial_E"',"\sboxed{e_p}" near end] &
0 \\
0 \arrow[r] &
C_{p} \arrow[r,"\phi"] \arrow[d,"\partial_C"',"\sboxed{c_{p-1}}" near end] &
D_{p} \arrow[r,"\psi"] \arrow[d,"\partial_D"',] &
E_{p} \arrow[r] \arrow[d,"\partial_E"'] &
0 \\
0 \arrow[r] &
C_{p-1} \arrow[r,"\phi"] &
D_{p-1} \arrow[r,"\psi"] &
E_{p-1} \arrow[r] &
0
\end{tikzcd}

\end{document}

在此处输入图片描述

答案2

有更好的 TikZ 方法(使用节点选项label):

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\tikzset{% my label style:
  myls/.style={
    draw, text height=height("$d$")
    }
  }
  
\begin{document}
\begin{tikzcd}[row sep=large,column sep=large]
0 \arrow[r] &
C_{p+1} \arrow[r,"\phi"] \arrow[d,"\partial_C"'] & |[label={[myls]d_{p+1}}]|D_{p+1}
  \arrow[r,"\psi"] \arrow[d,"\partial_D"'] &
|[label={[myls]e_{p+1}}]|E_{p+1}
  \arrow[r] \arrow[d,"\partial_E"'] &
0 \\
0 \arrow[r] &
|[label={[myls]45:c_p}]|C_{p} \arrow[r,"\phi"] \arrow[d,"\partial_C"'] &
|[label={[myls]45:d_p}]|D_{p} \arrow[r,"\psi"] \arrow[d,"\partial_D"',] &
|[label={[myls]45:e_p}]|E_{p} \arrow[r] \arrow[d,"\partial_E"'] &
0 \\
0 \arrow[r] &
|[label={[myls]45:c_{p-1}}]|C_{p-1} \arrow[r,"\phi"] &
D_{p-1} \arrow[r,"\psi"] &
E_{p-1} \arrow[r] &
0
\end{tikzcd}
\end{document}

在此处输入图片描述

相关内容