5

Consider the diagram arrows in the following example:

\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}

The arrows connected to the \cdots are crooked. Apparently they want to match the height of the points. But I want the arrows to flat horizontal. I use TikZ only because amscd does not support diagonal arrows.

How can I change the arrows to be horizontal?

2
  • Use tikz-cd instead. Mar 9 '15 at 16:35
  • Is your question answered by one of the posts? If not, please edit your question. If yes, please accept one answer here by clicking the check mark to its left and I will delete my comment here. Thank you.
    – LaRiFaRi
    May 3 '16 at 11:47
7

The best option here is to to switch to 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}

enter image description here

If you insist on using a matrix of math nodes, then the problem can be prevented either using the perpendicular coordinate system for the name nodes in the edges, as in

\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}

or using text height and text depth for your matrix nodes, as in

\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}
3

matrix of nodes fixes nodes alignment to base. This is the reason for the missalignments. You can change nodes alignment to center and all edges will be flat.

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.