为什么 tikzcd 命令无法编译

为什么 tikzcd 命令无法编译

我尝试绘制一个图表:

\[
\begin{tikzcd}[column sep=small]
                    &D^n \arrow{r}{e_\alpha^n}    &X\arrow{r} &X/(X-e_\beta^{n-1}(B^{n-1}))\\
S^{n-1}\arrow{r}{\cong} &\partial D^n \arrow{u}[hook] &D^{n-1} \arrow{u}[swap]{e_\beta^{n-1}} \arrow{r} &D^{n-1}/\partial D^{n-1} \arrow{u}[swap,dashed]{\cong} \arrow{r}{\cong} &S^{n-1}
\end{tikzcd}
\]

但是当我编译时,它只是说未定义的控制序列引用包含 \end{tikzcd} 的行,但没有给出任何原因。哪里出了问题?

PS 我已经包含了包裹

\usepackage{tikz}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\usepackage{tikz-cd}
\tikzset{commutative diagrams/.cd}

答案1

您的语法错误为

\arrow{u}[hook]

它应该是

\arrow[hook]{u}

类似地(虽然这不会产生错误),而不是

\arrow{u}[swap,dashed]{\cong} 

你应该使用

\arrow[swap,dashed]{u}{\cong} 

否则,该dashed选项将被忽略。代码:

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

\begin{document}

\[
\begin{tikzcd}[column sep=small]
& D^n \arrow{r}{e_\alpha^n} & X\arrow{r} & X/(X-e_\beta^{n-1}(B^{n-1})) \\
S^{n-1}\arrow{r}{\cong} & \partial D^n \arrow[hook]{u} & D^{n-1} \arrow{u}[swap]{e_\beta^{n-1}} \arrow{r} &D^{n-1}/\partial D^{n-1} \arrow[swap,dashed]{u}{\cong} \arrow{r}{\cong} &S^{n-1}
\end{tikzcd}
\]

\end{document}

如果您有最新版本tikz-cd(使用 PGF/TikZ 3.0 版),您会有更舒适的语法(使用库quotes):

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

\begin{document}

\[
\begin{tikzcd}[column sep=small]
& D^n \arrow[r,"e_\alpha^n"] & X\arrow[r] & X/(X-e_\beta^{n-1}(B^{n-1})) \\
S^{n-1}\arrow[r,"\cong"] & \partial D^n \arrow[u,hook] & D^{n-1} \arrow[u,swap,"e_\beta^{n-1}"] \arrow[r] &D^{n-1}/\partial D^{n-1} \arrow[u,swap,dashed,"\cong"] \arrow[r,"\cong"] &S^{n-1}
\end{tikzcd}
\]

\end{document}

在此处输入图片描述

相关内容