Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
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 1 '13 at 18:49

1 Answer 1

up vote 7 down vote accepted

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).

share|improve this answer
    
This is great, how can I lengthen the arrows? –  beethree Apr 1 '13 at 19:03
    
@beethree you can use row sep and/or column sep,for example: \begin{tikzcd}[row sep=huge,column sep=huge]...\end{tikzcd} (refer to the package documentation for other valid values) or even \begin{tikzcd}[row sep=90pt,column sep=200pt]...\end{tikzcd} –  Gonzalo Medina Apr 1 '13 at 19:09
    
Thank you, your code above worked great. \begin{tikzcd}[row sep=3.5 cm,column sep=3.5cm] gave me enough room. –  beethree Apr 1 '13 at 19:17
    
@beethree You're welcome. I added another example with the initial labels. –  Gonzalo Medina Apr 1 '13 at 19:18
    
You might want \text{Ker} to keep Ker from being a sequence of three italicized variables. Or use \DeclareMathOperator{\Ker}{Ker} . –  Ethan Bolker Apr 2 '13 at 1:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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