tikz-cd 中的交替列分隔符

tikz-cd 中的交替列分隔符

对于绘制 3-D 图表来说,手动设置列宽以在“实际”列分隔和考虑透视的列分隔之间交替有点繁琐:

\documentclass{article}
\usepackage{tikz-cd,calc}
\begin{document}
    \newlength\tilt
    \setlength\tilt{2.5em}
    \newlength\colsep
    \setlength\colsep{4.5em}
    \[
        \begin{tikzcd}[column sep={4.5em,between origins}, row sep=0.5em]
                      & [\tilt-\colsep] 0 \ar[rr] & [-\tilt]    & [\tilt-\colsep] A \ar[rr] \ar[dl] & [-\tilt]                                            & [\tilt-\colsep] G_1 \ar[rr] \ar[dl] \ar[ddrr,out=-90,in=180] & [-\tilt]                                         & [\tilt-\colsep] G_0 \ar[dd]\ar[dl] \ar[dd] \ar[rr] & [-\tilt]  & [\tilt-\colsep] X \ar[rr] & [-\tilt] & [\tilt-\colsep]  0 \\
            0 \ar[rr] &                           & F_2 \ar[rr] &                                   & F_1 \ar[rr, crossing over] \ar[ddrr,out=-90,in=180] &                                                              & F_0 \ar[dd, crossing over] \ar[rr,crossing over] &                                                    & Y \ar[rr] & [4mm]                     & 0,       &                    \\
                      &                           &             &                                   &                                                     &                                                              &                                                  & Z \ar[dl, equal]                                   &           &                           &          &                    \\
                      &                           &             &                                   &                                                     &                                                              & Z                                                &                                                    &           &                           &          &
        \end{tikzcd}
    \]
\end{document}

在此处输入图片描述

有什么办法可以做类似(伪代码)的事情\begin{tikzcd}[column sep={alternatingly \tilt and \colsep-\tilt,between origins}](我希望你得到我想要的)?

编辑:使用 tikz' matrix,它可以工作:

\documentclass{article}
\usepackage{tikz-cd,calc}
\begin{document}
    \newlength\tilt
    \setlength\tilt{5em}
    \newlength\colsep
    \setlength\colsep{4em}
    \[
        \begin{tikzpicture}[commutative diagrams/every diagram]
            \matrix (m) [matrix of math nodes, commutative diagrams/every cell, every even column/.style={column sep={\colsep-\tilt,between origins}},every odd column/.style={column sep={\tilt,between origins}}] {
                      & 0 &     & A &     & G_1 &     & G_0 &   & X &   & 0 \\
                    0 &   & F_2 &   & F_1 &     & F_0 &     & Y &   & 0 &   \\
            };
            \path[commutative diagrams/.cd, every arrow, every label]
                (m-1-2) edge (m-1-4)
                (m-1-4) edge (m-1-6)
                (m-1-6) edge (m-1-8)
                (m-1-8) edge (m-1-10)
                (m-1-10) edge (m-1-12)
                (m-2-1) edge (m-2-3)
                (m-2-3) edge (m-2-5)
                (m-2-5) edge (m-2-7)
                (m-2-7) edge (m-2-9)
                (m-2-9) edge (m-2-11)
                ;
        \end{tikzpicture}
    \]
\end{document}

但我喜欢 tikzcd 的\ar-syntax。有什么方法可以用 tikzcd 实现这个功能吗?

答案1

我会跳过空列并将每个奇数行向右移动。

代码

\documentclass[tikz]{standalone}
%\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{
  tilt/.initial=2.5em, colsep/.initial=4.5em,
  my tilted diagram/.style={
    column sep={\pgfkeysvalueof{/tikz/commutative diagrams/colsep},between origins},
    row sep={.5*(\pgfkeysvalueof{/tikz/commutative diagrams/colsep}),between origins},
    /tikz/every odd row/.append style={xshift=\pgfkeysvalueof{/tikz/commutative diagrams/tilt}}}}
\begin{document}
\begin{tikzcd}[my tilted diagram]
  0   \rar\dar
& A   \rar\dar
& G_1 \rar\dar\ar[ddr, out=-90, in=180]
& G_0 \rar\dar\ar[dd, crossing over]
& X   \rar\dar
& 0   \\
  0   \rar
& F_2 \rar
& F_1 \rar[crossing over] \ar[ddr, out=-90, in=180]
& F_0 \rar\ar[dd, crossing over]
& Y \rar
& 0 \\
& & & Z \dar[equal] \\
& & & Z
\end{tikzcd}
\end{document}

输出

在此处输入图片描述

答案2

tikzcd您可以使用以下方法做同样的事情[nodes={...}]

在此处输入图片描述

\documentclass{article}
\usepackage{tikz-cd,calc}
\begin{document}
    \newlength\tilt
    \setlength\tilt{5em}
    \newlength\colsep
    \setlength\colsep{4em}
    \[
    \begin{tikzcd}[nodes={every even column/.style={column sep={\colsep-\tilt,between origins}},every odd column/.style={column sep={\tilt,between origins}}}]
      & 0\arrow[rr] && A\arrow[rr] && G_1\arrow[rr] && G_0\arrow[rr] && X\arrow[rr] && 0\\
    0\arrow[rr] && F_2\arrow[rr] && F_1\arrow[rr] && F_0\arrow[rr] && Y\arrow[rr] && 0 
    \end{tikzcd}
    \]
\end{document}

相关内容