0

I'm trying to draw this commutative diagram (source: Elements of Algebraic Topology by James Munkres). I know how to draw the diagram using tikzcd without the boxes. Can someone help me about how to add these boxes on the tikzcd diagram?

1
  • 1
    Please provide the code for the tikzcd version. AFAIR tikzcd can name the main cells, and thus you can subsequently add the boxes relative to these cells.
    – daleif
    Dec 23, 2021 at 13:50

2 Answers 2

2

We can place the boxes in the middle as labels “near end”, but a bit lowered and with smashed depth. For the upper boxes, I use \overset, but making the boxes zero width for safety.

\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}

enter image description here

1
  • @AtonuRoyChowdhury Maybe there are better TikZ ways, but… ;-)
    – egreg
    Dec 23, 2021 at 21:10
2

There are better TikZ ways (using the node option 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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .