# How to adjust or move the labels of arrows in tikz matrix of math nodes

I am trying to label crossing arrows in my tikz-matrix diagram. By default, the label is placed half-way of the path. Since the arrows cross half-way too, the labelling becomes ambiguous:

How can I 'move' the label downwards or upwards? Or is there a better environment for drawing this diagram?

Here is the tikz code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=4em,
column sep=0.2em]{
V& \quad \hookrightarrow \quad & H & \cong& H'& \quad \hookrightarrow &V' \\
Q_+& \quad \hookrightarrow \quad & Q & \cong& Q '& \quad \hookrightarrow &Q_+' \\
};
\path[-stealth]
(m-1-1) edge [densely dotted] node [left] {$J_1'$} (m-2-5)
(m-1-3) edge (m-2-7)
(m-2-1) edge  (m-1-5)
(m-2-3) edge [densely dotted] (m-1-7);
\end{tikzpicture}

\end{document}

-
Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. You're missing a semi-colon at the end of your \path. I suggest using [xshift=-1.5em,yshift=.5em,left] or something like that. –  Jubobs May 6 '13 at 8:15
You can add the option anchor=south or anchor=north to the node options, so that it reads e.g. [left, anchor=south] –  Yori May 6 '13 at 8:15
Oh, and maybe also add e.g. pos=0.3, which instructs TikZ to put the label at around 30% of the edge (instead of 50%, i.e., the midpoint). anchor=north, pos=0.1 seems good to me. Add e.g. xshift=2pt or yshift=2pt for better positioning. –  Yori May 6 '13 at 8:24
There are also two (generally) useful keys: near start and near end. –  kan May 6 '13 at 8:28
I also want to drop some useful keys: auto and swap (instead of left, top, etc.). –  Qrrbrbirlbel May 6 '13 at 8:30

## 1 Answer

I'd like to present an answer using the beautiful package tikz-cd.

Update

Here is a solution based on the version v.0.3c, the most recent.

\documentclass{amsart}
\usepackage{tikz-cd} %some features in this code require v.0.3c
\begin{document}
\begin{tikzcd}
V \arrow[densely dotted, end anchor={[xshift=-3ex]north east}]{rd}[swap, pos=0.4, description]{J_1'} \arrow[hookrightarrow]{r}
& H \cong H' \arrow[start anchor={[xshift=1.5ex]south west}, densely dotted]{rd}\arrow[hookrightarrow]{r}
& V' \\

Q_+\arrow[densely dotted, end anchor={[xshift=-3ex]south east}]{ru}\arrow[hookrightarrow]{r}
& Q \cong Q' \arrow[hookrightarrow]{r}
& Q_+
\end{tikzcd}
\end{document}


The Output

Some Useful Anchors available (the following image is a screenshot from this tutorial that influenced the package tikz-cd):

Some preliminary remarks: the newest version has a very clean interface to anchors (and I exploit anchors quite heavily in this solution). However, the old answer based on the version v.0.3a is here, in case you don't have access to the new version just like I did not have.

I highly recommend the following solution, which leaves no room for ambiguity about which arrow is being called J1'.

\documentclass{amsart}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
V \arrow[densely dotted, end anchor=40]{rd}[swap, pos=0.77, description]{J_1'} \arrow[hookrightarrow]{r}
& H \cong H' \arrow[start anchor=210, densely dotted]{rd}\arrow[hookrightarrow]{r}
& V' \\

Q_+\arrow[densely dotted, end anchor=-60]{ru}\arrow[hookrightarrow]{r}
& Q \cong Q' \arrow[hookrightarrow]{r}
& Q_+
\end{tikzcd}
\end{document}


The output:

Confusing-to-the-reader solution:

\documentclass{amsart}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
V \arrow[densely dotted, end anchor=40]{rd}[swap, pos=0.65]{J_1'} \arrow[hookrightarrow]{r}
& H \cong H' \arrow[start anchor=210, densely dotted]{rd}\arrow[hookrightarrow]{r}
& V' \\

Q_+\arrow[densely dotted, end anchor=-60]{ru}\arrow[hookrightarrow]{r}
& Q \cong Q' \arrow[hookrightarrow]{r}
& Q_+
\end{tikzcd}
\end{document}


The Output

-
Thank you for this thorough introduction into tikz-cd... I will just shrink the hooked arrows, as they are mathematical relations rather than arrows. –  Jan May 6 '13 at 11:29
@Jan Glad to have been of help. Sure, do as you please! :) –  kan May 6 '13 at 11:34