此 tikz 图表有弯曲的箭头

此 tikz 图表有弯曲的箭头

考虑以下示例中的图表箭头:

\documentclass[a4paper,10pt,psamsfonts]{amsart}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amscd}
\usepackage{tikz}
\usepackage{sidecap}
\usetikzlibrary{matrix,arrows}
\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em]
  {
 A &
 B &
 \cdots &
 C 
 \\
 D &
 E &
 \cdots &
 F
 \\
  };
  \path[-stealth]
    (m-1-1) edge node [above] {$f$} (m-1-2)
    (m-1-2) edge node [above] {$f$} (m-1-3)
    (m-1-3) edge node [above] {$f$} (m-1-4)
(m-2-1) edge node [above] {$f$} (m-2-2)
(m-2-2) edge node [above] {$f$} (m-2-3)
(m-2-3) edge node [above] {$f$} (m-2-4)
(m-2-1) edge node [above] {$g$} (m-1-2)
(m-2-2) edge node [above] {$g$} (m-1-3)
(m-2-3) edge node [above] {$g$} (m-1-4)
;
\end{tikzpicture}
\end{document}

连接到的箭头\cdots是弯曲的。显然他们想匹配点的高度。但我希望箭头水平放置。我使用 TiZ 仅限于amscd不支持对角箭头。

我怎样才能将箭头改为水平?

答案1

最好的选择是切换到tikz-cd

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

\begin{document}

\begin{tikzcd}
 A\arrow[r,"f"] &
 B\arrow[r,"f"] &
 \cdots\arrow[r,"f"] &
 C 
 \\
 D\arrow[r,"f"]\arrow[ur,"g"] &
 E\arrow[r,"f"]\arrow[ur,"g"] &
 \cdots\arrow[r,"f"]\arrow[ur,"g"] &
 F
\end{tikzcd}

\end{document}

在此处输入图片描述

如果你坚持使用matrix of math nodes,那么可以通过使用边中的名称节点的垂直坐标系来避免这个问题,就像

\documentclass[a4paper,10pt,psamsfonts]{amsart}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}

\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em]
  {
 A &
 B &
 \cdots &
 C 
 \\
 D &
 E &
 \cdots &
 F
 \\
  };
  \path[-stealth]
    (m-1-1.east) edge node [above] {$f$} (m-1-2.west|-m-1-1.east)
    (m-1-2.east) edge node [above] {$f$} (m-1-3.west|-m-1-1.east)
    (m-1-3.east|-m-1-1.east) edge node [above] {$f$} (m-1-4.west|-m-1-1.east)
(m-2-1.east) edge node [above] {$f$} (m-2-2.west|-m-2-1.east)
(m-2-2.east) edge node [above] {$f$} (m-2-3.west|-m-2-1.east)
(m-2-3.east|-m-2-1.east) edge node [above] {$f$} (m-2-4.west|-m-2-1.east)
(m-2-1) edge node [above] {$g$} (m-1-2)
(m-2-2) edge node [above] {$g$} (m-1-3)
(m-2-3) edge node [above] {$g$} (m-1-4)
;
\end{tikzpicture}
\end{document}

或者使用 text heighttext depth作为矩阵节点,例如

\documentclass[a4paper,10pt,psamsfonts]{amsart}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}

\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em,nodes={text height=1.75ex,text depth=0.25ex}]
  {
 A &
 B &
 \cdots &
 C 
 \\
 D &
 E &
 \cdots &
 F
 \\
  };
  \path[-stealth]
    (m-1-1) edge node [above] {$f$} (m-1-2)
    (m-1-2) edge node [above] {$f$} (m-1-3)
    (m-1-3) edge node [above] {$f$} (m-1-4)
(m-2-1) edge node [above] {$f$} (m-2-2)
(m-2-2) edge node [above] {$f$} (m-2-3)
(m-2-3) edge node [above] {$f$} (m-2-4)
(m-2-1) edge node [above] {$g$} (m-1-2)
(m-2-2) edge node [above] {$g$} (m-1-3)
(m-2-3) edge node [above] {$g$} (m-1-4)
;
\end{tikzpicture}
\end{document}

答案2

matrix of nodes将节点对齐固定为base。这是错位的原因。您可以将节点对齐更改为 ,center这样所有节点edges都将平坦。

\documentclass[a4paper,10pt,psamsfonts]{amsart}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amscd}
\usepackage{tikz}
\usepackage{sidecap}
\usetikzlibrary{matrix,arrows}
\begin{document}
\begin{tikzpicture}
  \matrix (m) [matrix of math nodes,
           nodes={anchor=center}, % Changes node's anchor from `base` to `center`
           row sep=3em,column sep=4em,minimum width=2em]
  {
 A &
 B &
 \cdots &
 C 
 \\
 D &
 E &
 \cdots &
 F
 \\
  };
  \path[-stealth]
    (m-1-1) edge node [above] {$f$} (m-1-2)
    (m-1-2) edge node [above] {$f$} (m-1-3)
    (m-1-3) edge node [above] {$f$} (m-1-4)
(m-2-1) edge node [above] {$f$} (m-2-2)
(m-2-2) edge node [above] {$f$} (m-2-3)
(m-2-3) edge node [above] {$f$} (m-2-4)
(m-2-1) edge node [above] {$g$} (m-1-2)
(m-2-2) edge node [above] {$g$} (m-1-3)
(m-2-3) edge node [above] {$g$} (m-1-4)
;
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容