# How can I align TikZ nodes of a commutativity diagram?

I have a TikZ picture:

\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=0em,column sep=3em,minimum width=2em] {
E_1 & H^+ \\
E_1^\perp & H^- \\
&\R^{2m}\backslash\left\{H^+\cap H^-\right\}\\};
\path[-stealth]
(m-1-1) edge (m-1-2)
(m-2-1) edge (m-2-2)
edge (m-1-2)
edge (m-3-2);
\end{tikzpicture}


So far so good. It looks like this:

Two questions:

1. How can I align the the right nodes horizontally to the left, so that the left side of the right nodes is on one vertical line?
2. How can I align the right or left nodes vertically, so that the two horizontal arrows are exactly horizontal? Right now they are a little tilted.
• While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially important for tikz as there are numerous libraries. Jan 13, 2016 at 11:04

By default a matrix of nodes anchors (place and align) nodes on their baseline, but you can change it fixing a new anchor point:

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{matrix}
\usepackage{amsmath}

\begin{document}

\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=0em,column sep=3em,minimum width=2em, nodes={anchor=west}] {
E_1 & H^+ \\
E_1^\perp & H^- \\
&R^{2m}\backslash\left\{H^+\cap H^-\right\}\\};
\path[-stealth]
(m-1-1) edge (m-1-2)
(m-2-1) edge (m-2-2)
edge (m-1-2)
edge (m-3-2);
\end{tikzpicture}
\end{document}


• But now the lowest arrow doesn't end in the middle of the right element's side. How to correct this?
– Rob
Jan 13, 2016 at 13:02
• @Rob edge (m-3-2) finishes the line at node's center but stops drawing it a node's hidden border. Same happens with line going to H+ from second line. A possible solution could be edge (m-3-2.west) which will finish at central point on node's west border. Jan 13, 2016 at 14:53

A version with tikz-cd; only a small adjustment needs to be made for an arrow.

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

\begin{document}

\begin{tikzcd}[
cells={nodes={anchor=west}},
end anchor={west},
row sep=1ex,
column sep=large,
]
E_1 \arrow[r] & H^+ \\
E_1^\perp
\arrow[ru,end anchor=south west]
\arrow[r]
\arrow[rd] & H^- \\
& \mathbb{R}^{2m}\setminus (H^+\cap H^-)
\end{tikzcd}

\end{document}


Here's a minimal version using tikz-cd package.

## Code

\documentclass[letterpaper,11pt,reqno]{amsart}
\usepackage{tikz-cd}

\begin{document}
$\begin{tikzcd}[row sep=2mm, column sep=1.5cm, cells={anchor=west}] E_1 \arrow[r] & H^+ \\ E_1^\perp \arrow[ur]\arrow[r]\arrow[dr, end anchor={west}] & H^- \\ & \mathbb{R}^{2m} \setminus\left\{H^+\cap H^-\right\}\ \\ \end{tikzcd}$
\end{document}