10

How can I add text to both the top and bottom of a path? My commutative diagram below is 90% complete. I would, however, like text={${gKer({\varphi}){\mapsto}{\varphi(G)}}$} following the path below the arrow and \cong following the path above the same arrow.

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}

\node (A) {$G$};
\node (B) [right of=A] {$G'$};
\node (C) [below of=A] {$G/Ker(\varphi)$};

\draw[->>] (A) --(B) node[above,midway] {$\varphi$};
\draw[->,postaction={decorate,decoration={text along path,text align=center,text={${\pi}{\;}$}}}] (A) to node[swap] {} (C);
\draw[->,postaction={decorate,decoration={text along path,text align = center,text={${gKer({\varphi}){\mapsto}{\varphi(G)}}$}}}] (C) to node[swap] {} (B);

\end{tikzpicture}

\end{document}
beethree
  • 639
  • 4
    Why do you use the text along path decoration on a straight path? It would be simpler to do \path (a) -- node[below] {stuff} node[above] {other stuff} (b) ;. Also, take a look at the tikz-cd package. By the way, the syntax <direction> of=<node> is deprecated (and you do not use the positioning library that way): [1], [2] – Qrrbrbirlbel Apr 01 '13 at 18:49

1 Answers1

13

I would suggest you tu use the tikz-cd package for your commutative diagrams; also, since the problematic label is not really the name of a map, but rather its action, I would also suggest you to describe the map outside the diagram (otherwise, the diagram might result too crowded):

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

\DeclareMathOperator{\Ker}{Ker}

\begin{document}

\[
\begin{tikzcd}
G\arrow[twoheadrightarrow]{r}{\varphi}\arrow{d}{\pi} & G' \\
G/\Ker(\varphi)\arrow[sloped,swap]{ur}[near start]{\tau}[swap]{\cong}
\end{tikzcd}
\]
where $\tau:G/\Ker(\varphi)\rightarrow G'$ is defined by $g\Ker({\varphi}){\mapsto}{\varphi(G)}$.

\end{document}

enter image description here

Of course, you can draw the diagram with the originally requested labels, perhaps increasing the distance between nodes:

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

\DeclareMathOperator{\Ker}{Ker}

\begin{document}

\[
\begin{tikzcd}[row sep=60pt,column sep=huge]
G\arrow[twoheadrightarrow]{r}{\varphi}\arrow{d}{\pi} & G' \\
G/\Ker(\varphi)\arrow[sloped,swap]{ur}[pos=0.15]{g\Ker({\varphi}){\mapsto}{\varphi(G)}}[swap]{\cong}
\end{tikzcd}
\]

\end{document}

enter image description here

Notice the use of

\DeclareMathOperator{\Ker}{Ker}

(requires the amsmath package) to produce the correct shape for the Ker operator; (I initially overlooked this, but Ethan Bolker signaled it out in a comment).

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128