1

I am interested in a streamlined method of leveling the arrows in the following diagram (a very much scaled down example)

\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=3.5em, column sep=3.5em]
 {A & A[1] \\
  A' & A'[1] \\};
\path[-stealth]
 (m-1-1) edge node [above] {$x$} (m-1-2)
 (m-2-1) edge node [above] {$y$} (m-2-2)
 (m-1-1) edge node [right] {$z$} (m-2-1)
 (m-1-2) edge node [right] {$t$} (m-2-2);
\end{tikzpicture}

which produces

As you can see, the horizontal arrows are not so horizontal after all. Per answers and comments to this and this question I learned that a) adding nodes={anchor=east} straightens the horizontal arrows, but skews the vertical ones, and b) replacing (m-1-1) edge node [above] {$x$} (m-1-2) with (m-1-1) edge node [above] {$x$} (m-1-1.west -| m-1-2.west) and so on does the job, but is frankly a bit of a chore. So is c) adding \phantom{foo} to each node to ensure they have the same height (or rather the same centers).

As I have quite a few different and much more complicated diagrams to draw (and already drafted as matrices), is there any good way to globally fix the grid between which the arrows are drawn in each diagram in tikz matrix environment? I wouldn't be surprised if I am missing something obvious (actually, I am hoping that), as this seems like a thing that should be done easier than introducing phantom characters to the text.

3

A matrix of nodes or a matrix of math nodes fixes nodes' anchors to base. This means that when nodes' contents are not similar, nodes' centers and nodes' baseline anchor are not at same height. In this case A and A[1] have different base lines.

(m-1-1) and (m-1-2) are references to m-1-1.center and m-1-2.center anchors which are not on a horizontal line.

If you change nodes' anchors to center, nodes will change their vertical alignment to place centers over an horizontal line. nodes={anchor=center} will do the work.

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=3.5em, column sep=3.5em, nodes={anchor=center}]
 {A & A[1] \\
  A' & A'[1] \\};
\path[-stealth]
 (m-1-1) edge node [above] {$x$} (m-1-2)
 (m-2-1) edge node [above] {$y$} (m-2-2)
 (m-1-1) edge node [right] {$z$} (m-2-1)
 (m-1-2) edge node [right] {$t$} (m-2-2);
\end{tikzpicture}
\end{document}

enter image description here

1
  • Thank you! I misunderstood what an anchor is (I am not fluent in TikZ). Now I am very surprised that the linked questions, on essentially the same problem, didn't get this answer. I was sure there should be such a global solution instead of a node-by-node workaround, but was unable to piece it together.
    – lemon314
    Feb 13 at 0:12

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.