Manipulate cell width in tikz-cd
Solution 1
You have to fool tikz-cd
into thinking that the lower right corner object has zero width; then you can artificially shorten the arrow to it.
\documentclass{article}
\usepackage{tikz-cd,mathtools}
\begin{document}
\begin{tikzcd}
A \arrow{r} \arrow{d} & B \arrow{r} \arrow{d} & C \arrow{d} \\
D \arrow{r} & E \arrow[end anchor={[xshift=-1.25em]}]{r}
& \mathclap{F \oplus G}
\end{tikzcd}
\end{document}
The command \mathclap
is provided by mathtools
.
Sincerely, I prefer the default version.
Solution 2
Sure, you can set C
inside a box that is exactly the width of F \oplus G
:
\documentclass{article}
\usepackage{calc,tikz-cd}
\begin{document}
\begin{tikzcd}
A \rar \dar & B \rar \dar & \makebox[\widthof{$F \oplus G$}]{$C$} \dar \\
D \rar & E \rar & F \oplus G
\end{tikzcd}
\end{document}
calc
's command \widthof
is used to measure the width of F \oplus G
, setting C
in a centred box of that exact width.
Solution 3
Not a new problem:
- How to ensure consecutive diagonal arrows form a straight line?
- Tikz-cd: How can I arrange diagonal arrows parallel?
Code
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}\centering
\begin{tikzcd}[
matrix of math nodes maybe/.append style={
/tikz/column 3/.append style={
/tikz/nodes={
text width=\widthof{$F\oplus G$},
align=center}}}]
A \rar \dar & B \rar \dar & C \dar \\
D \rar & E \rar & F \oplus G
\end{tikzcd}\medskip\par
\begin{tikzcd}
A \rar \dar & B \rar \dar &
|[text width=\widthof{$F\oplus G$}, align=center]|C \dar \\
D \rar & E \rar & F \oplus G
\end{tikzcd}\bigskip
\begin{tikzcd}
A \rar \dar & B \rar \dar & C \dar \\
D \rar & E \rar & |[overlay]| F \oplus G
\end{tikzcd}\medskip\par
\begin{tikzcd}[nodes=overlay, row sep=large, column sep=large]
A \rar \dar & B \rar \dar & C \dar \\
D \rar & E \rar & F \oplus G
\end{tikzcd}\bigskip
\begin{tikzcd}[/tikz/column sep=
{\pgfkeysvalueof{/tikz/commutative diagrams/column sep/large},between origins}]
A \rar \dar & B \rar \dar & C \dar \\
D \rar & E \rar & F \oplus G
\end{tikzcd}\bigskip
\end{document}
Output
Related videos on Youtube
DavidR
Updated on June 16, 2022Comments
-
DavidR less than a minute
This is something of a nitpick, but I'm having some trouble getting to grips with
tikz-cd
. I'm not sure of the TikZ terminology, but I think I'm trying to find a way to manipulate cell widths. Here's a minimal example to illustrate my problem:\documentclass{minimal} \usepackage{tikz, tikz-cd} \begin{document} \begin{tikzcd} A \rar \dar & B \rar \dar & C \dar \\ D \rar & E \rar & F \oplus G \end{tikzcd} \end{document}
I'd like to make the arrow from
B
toC
the same length as that fromE
toF+G
. My first thought was that I should pad the box (cell?) containingC
so it's the same width as the one containing F + G. I can sort of do it by replacingC
with\quad C \quad
, but surely there must be a better way! Does anyone know how to do this? -
DavidR over 8 yearsOh, that's a nice way of doing it - not quite what I had in mind but it seems to be what I was looking for. Thanks!