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.

I am trying to draw a commutative diagram using Tikz, and am having a bit of trouble adding arrowheads between all of the functions I found some code for this online,and I have modified it, but am only getting an arrow between X and Y, and not any of the other functions. Here is what I have:

\begin{document}
\documentclass[12pt,a4paper,oneside]{report}
\usepackage[left=2.00cm,right=2.00cm,top=2.45cm,bottom=2.5cm]{geometry}
\usepackage{amsmath,amssymb,amscd,amstext}
\usepackage{color,epsfig,fancyhdr,latexsym,slashed}
\usepackage[thmmarks]{ntheorem}
\usepackage{tikz, subfig}
\usepackage{verbatim}
\usetikzlibrary{matrix,arrows}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=3em,
column sep=2.5em, text height=1.5ex, text depth=0.25ex]
{ X & & Y \\
& Z & \\ };
%\draw[->] (m-1-1) – (m-1-3);
  \path[->,font=\normalsize]
  (m-1-1) edge node[auto] {$ f $} (m-1-3)
  edge node[auto] {$ h $} (m-2-2)
  (m-1-3) edge node[auto] {$ g $} (m-2-2);
\end{tikzpicture}

Thanks.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Why not using tikz-cd?

\documentclass[a4paper]{report}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
X \arrow{rr}{f} \arrow{rd}[swap]{h}  && Y \arrow{dl}{g} \\
& Z
\end{tikzcd}

\end{document}

The swap key puts the label on the opposite side as the default.

enter image description here

Another approach is with Xy-pic

\documentclass[a4paper]{report}
\usepackage[all,cmtip]{xy}

\begin{document}
\xymatrix{
  X \ar[rr]^f \ar[dr]_h && Y \ar[dl]^g \\
  & Z
}
\end{document}

which gives

enter image description here

share|improve this answer
    
Thanks for all the help. I was not aware of tikz-cd at all when I posted this as I am very new to tikz; but that is what I was looking for. Thanks again. –  Michael Dykes May 20 '12 at 16:18

Your mwe has some mistakes like \begin{document and \end{document}. Once corrected I get this.

\documentclass[12pt,a4paper,oneside]{report}
\usepackage[left=2.00cm,right=2.00cm,top=2.45cm,bottom=2.5cm]{geometry}
\usepackage{amsmath,amssymb,amscd,amstext}
\usepackage{color,epsfig,fancyhdr,latexsym,slashed}
\usepackage[thmmarks]{ntheorem}
\usepackage{tikz, subfig}
\usepackage{verbatim}
\usetikzlibrary{matrix,arrows}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=3em,
column sep=2.5em, text height=1.5ex, text depth=0.25ex]
{ X & & Y \\
& Z & \\ };
% \draw[->] (m-1-1) -- (m-1-3);
 \path[->,font=\normalsize]
  (m-1-1) edge node[above] {$ f $} (m-1-3)
  edge node[left] {$ h $} (m-2-2)
  (m-1-3) edge node[right] {$ g $} (m-2-2);
\end{tikzpicture}
\end{document}

enter image description here

It is not clear from your question whether you need any more arrows. Some clarification may be needed here.

share|improve this answer

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.