Centering a tikz-cd
You can employ a TikZ function to center the whole picture to the text (not the page when different margins are used).
These are trim left
and trim right
. Setting both to the same coordinate means that the picture will have no horizontal width and since \[ … \]
will center its content on its own it will then center the picture on that coordinate. If that coordinate is set to the center of the whole picture then the whole picture will be centered around its center.
If you need this often, it be wise to define your own style for it which is why I defined a center picture
style for that.
(The \[ … \]
is not necessary for a tikz-cd
diagram since it will be using math-mode for the cells anyway, instead of \[ … \]
the center
environment might be used but the vertical spacing might be different.)
Or a smaller picture
I'm no expert on commutative diagrams and what the rules are but I've added two separte examples:
- The first one (with
down and trim
for the nodes of the first row) aligns the first row in a staircase.
- The second one (with
downup and trim
) only alternates the vertical placement.
Both trim the bounding boxes of the nodes by 1cm
on both sides.
I've chosen 1.5\baselineskip
randomly, it might be wiser to set this value in relation to the diagram's setup (vertical spacing and sizes of nodes).
If you're using formulas inside the cells that are very high or low much more manual control will be needed.
Here, all nodes are still in the same \matrix
row but are set at a different height.
For more complex diagrams it might be wise to just distribute these formulas on different nodes, either again with trim node
or a negative column sep
eration.
Code
\documentclass{report}
\usepackage[english]{babel}
\usepackage{amsmath, amssymb, tikz-cd, blindtext}
\newcommand{\C}{\mathbb{C}}
\tikzset{
trim node/.default=1cm,
trim node/.style={
overlay,
append after command={% restore smaller bounding box
([xshift={+#1}]\tikzlastnode.north west)
([xshift={+-#1}]\tikzlastnode.south east)}},
down and trim/.default=1cm,
down and trim/.style={
yshift=-(\pgfmatrixcurrentcolumn-1)*1.5\baselineskip,
trim node={#1}},
downup and trim/.default=1cm,
downup and trim/.style={
yshift=iseven(\pgfmatrixcurrentcolumn) ? -1.5\baselineskip : 0pt,
trim node={#1}},
-|/.style={to path={-|(\tikztotarget)\tikztonodes}},
|-/.style={to path={|-(\tikztotarget)\tikztonodes}},
-| sl/.style={-|, xslant=-1},
|- sl/.style={|-, xslant= 1},
center picture/.style={
trim left=(current bounding box.center),
trim right=(current bounding box.center)}}
\begin{document}
\blindtext
\[
\begin{tikzcd}[column sep = 1em, center picture]
K^0_{S^1}(E_0 \times \C, p_1^*P_k) \rar \dar
& K_{S^1}^0(U \times \C) \oplus K^0_{S^1}(V \times \C) \rar \dar
& K_{S^1}^0(U\cap V \times \C) \rar \dar
& K^1_{S^1}(E_0 \times \C, p_1^*P_k) \dar \\
K^0_{S^1}(E_0, P_k) \rar
& K_{S^1}^0(U) \oplus K^0_{S^1}(V) \rar
& K_{S^1}^0(U \cap V) \rar
& K^1_{S^1}(E_0, P_k)
\end{tikzcd}
\]
\blindtext
\[
\begin{tikzcd}[column sep = 1em, /tikz/row 1/.append style={nodes=down and trim}]
K^0_{S^1}(E_0 \times \C, p_1^*P_k) \rar[-|] \dar
& K_{S^1}^0(U \times \C) \oplus K^0_{S^1}(V \times \C) \rar[-|] \dar
& K_{S^1}^0(U\cap V \times \C) \rar[-|] \dar
& K^1_{S^1}(E_0 \times \C, p_1^*P_k) \dar \\
K^0_{S^1}(E_0, P_k) \rar
& K_{S^1}^0(U) \oplus K^0_{S^1}(V) \rar
& K_{S^1}^0(U \cap V) \rar
& K^1_{S^1}(E_0, P_k)
\end{tikzcd}
\]
\blindtext
\[
\begin{tikzcd}[column sep = 1em, /tikz/row 1/.append style={nodes=downup and trim}]
K^0_{S^1}(E_0 \times \C, p_1^*P_k) \rar[-| sl] \dar
& K_{S^1}^0(U \times \C) \oplus K^0_{S^1}(V \times \C) \rar[|- sl] \dar
& K_{S^1}^0(U\cap V \times \C) \rar[-| sl] \dar
& K^1_{S^1}(E_0 \times \C, p_1^*P_k) \dar \\
K^0_{S^1}(E_0, P_k) \rar
& K_{S^1}^0(U) \oplus K^0_{S^1}(V) \rar
& K_{S^1}^0(U \cap V) \rar
& K^1_{S^1}(E_0, P_k)
\end{tikzcd}
\]
\blindtext
\end{document}
Output

chngpage
package and wrap the thing (including\[...\]
) in ` \begin{adjustwidth}{-3cm}{-3cm}...\end{adjustwidth}`adjustwith
effect can be done with TikZ itself:trim left={([xshift=3cm]current bounding box.west)}, trim right={([xshift=-3cm]current bounding box.east)}
.