如何使箭头接触 tikzcd 中的方框表达式?

如何使箭头接触 tikzcd 中的方框表达式?

我有一个结构如下的图表:

\begin{tikzcd}
  \boxed{B} \arrow[d, hookrightarrow, "{f}"'] \arrow[r, "{x}"]
& \boxed{C} \arrow[d, hookrightarrow, "{g}"'] \arrow[r, dotted, "{y}"] 
& \boxed{D} \arrow[d, hookrightarrow, "{h}"']
\\
  \boxed{E} & \boxed{F} & \boxed{G}
\end{tikzcd}

它产生以下输出:

盒装示例输出

我怎样才能让箭头刚好接触到方框,使它们看起来连在一起?tikzcd 是解决这个问题的最佳方法吗?

答案1

最简单的选择可能是放弃\boxed并改用draw

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={draw}}]
  B \arrow[d, hookrightarrow, "{f}"'] \arrow[r, "{x}"]
& C \arrow[d, hookrightarrow, "{g}"'] \arrow[r, dotted, "{y}"] 
& D \arrow[d, hookrightarrow, "{h}"']
\\
  E & F & G
\end{tikzcd}
\end{document}

在此处输入图片描述

您可以将内外 sep 设置为 0。

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={outer sep=0pt,inner sep=0pt}}]
  \boxed{B} \arrow[d, hookrightarrow, "{f}"'] \arrow[r, "{x}"]
& \boxed{C} \arrow[d, hookrightarrow, "{g}"'] \arrow[r, dotted, "{y}"] 
& \boxed{D} \arrow[d, hookrightarrow, "{h}"']
\\
  \boxed{E} & \boxed{F} & \boxed{G}
\end{tikzcd}
\end{document}

在此处输入图片描述

如果你只希望水平箭头接触,你可以这样做

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[cells={nodes={outer xsep=0pt,inner xsep=0pt}}]
  \boxed{B} \arrow[d, hookrightarrow, "{f}"'] \arrow[r, "{x}"]
& \boxed{C} \arrow[d, hookrightarrow, "{g}"'] \arrow[r, dotted, "{y}"] 
& \boxed{D} \arrow[d, hookrightarrow, "{h}"']
\\
  \boxed{E} & \boxed{F} & \boxed{G}
\end{tikzcd}
\end{document}

在此处输入图片描述

或者,您也可以将箭头缩短一个负值。我添加了一种样式touching,将箭头延长了标准内距加外距。

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\tikzset{touching/.style={shorten >=-4pt,shorten <=-4pt}}
\begin{document}
\begin{tikzcd}
  \boxed{B} \arrow[d, hookrightarrow, "{f}"'] \arrow[r, "{x}",touching]
& \boxed{C} \arrow[d, hookrightarrow, "{g}"'] \arrow[r, dotted, "{y}",touching] 
& \boxed{D} \arrow[d, hookrightarrow, "{h}"']
\\
  \boxed{E} & \boxed{F} & \boxed{G}
\end{tikzcd}
\end{document}

在此处输入图片描述

相关内容