7

I've just started using TikZ and need to create a simple triangle commutative diagram like this one. enter image description here

The closest I've been able to get is this. enter image description here

How do I get the h arrow to go from A2 to A3? Everything I've tried just causes errors.

Here's my current code:

\begin{tikzcd}[column sep=small]
A \arrow{r}{i}  \arrow{rd}{g} 
  & A3 \arrow{d}{h} \\
    & A2
\end{tikzcd}
jaia
  • 173
  • 1
  • 1
  • 4

1 Answers1

11

Update

A better syntax has evolved with time, which has several advantages due to improvements in TikZ and is now recommended.

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

\begin{document}

[ \begin{tikzcd} & A \arrow[dr,"g"] \ B \arrow[ur,"f"] \arrow[rr,"h"] && C \end{tikzcd} ] [ \begin{tikzcd}[row sep=2.5em] & A \arrow[dr,"g"] \ B \arrow[ur,"f"] \arrow[rr,"h"] && C \end{tikzcd} ] [ \begin{tikzcd}[column sep=1.5em] & A \arrow[dr,"g"] \ B \arrow[ur,"f"] \arrow[rr,"h"] && C \end{tikzcd} ] \end{document}

Original answer

The basic idea for triangular diagrams is to consider more columns, in this case three; you may want to play with column sep or row sep in order to get better distances, as shown.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\[
\begin{tikzcd}
 & A \arrow{dr}{g} \\
B \arrow{ur}{f} \arrow{rr}{h} && C
\end{tikzcd}
\]
\[
\begin{tikzcd}[row sep=2.5em]
 & A \arrow{dr}{g} \\
B \arrow{ur}{f} \arrow{rr}{h} && C
\end{tikzcd}
\]
\[
\begin{tikzcd}[column sep=1.5em]
 & A \arrow{dr}{g} \\
B \arrow{ur}{f} \arrow{rr}{h} && C
\end{tikzcd}
\]
\end{document}

enter image description here


If you want to try this with QTikZ, you need a suitable template; create the text file tikz-cd-template.pgs with

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
<>
\end{document}

Choose the template and then paste the part of the above code which is between \begin{document} and \end{document} in the input window for QTikZ. Here's a picture of the result.

If you have an old version of tikz-cd (which might be the case on Ubuntu or other GNU/Linux boxes) it may be necessary to start the diagram with {}:

\[
\begin{tikzcd}
{} & A \arrow{dr}{g} \\
B \arrow{ur}{f} \arrow{rr}{h} && C
\end{tikzcd}
\]

enter image description here

egreg
  • 1,121,712
  • For some reason, your code doesn't work on my system (TeXLive running on Ubuntu 14.04 and using QTikZ for graphics editing and preview). Here's the error I'm getting: `Missing character: There is no A in font nullfont!

    [LaTeX] Line 2: Package pgfbasematrix Error: Single ampersand used with wrong catcode. [LaTeX] Line 2: See the pgfbasematrix package documentation for explanation. ...
    l.-5 &A \arrow{dr}{g} \

    [LaTeX] Line 2: ==> Fatal error occurred, no output PDF f`

    – jaia Jul 14 '14 at 20:51
  • @jaia Hmm, are you using that inside the argument to a command? What TeX distribution are you using? – egreg Jul 14 '14 at 20:54
  • I'm using the latest version of TeX Live. Not sure what you mean by "inside the argument to a command". (I'm mostly a LyX user and rarely deal with straight LaTeX.) I just pasted everything between the \begin{tikzcd} and \end{tikz} tags between those same tags in QTikZ. – jaia Jul 14 '14 at 21:02
  • Also, could you please point me to a good explanation of the column thing and how that works? – jaia Jul 14 '14 at 21:04
  • @jaia Sorry, but I know nothing of QTikZ and LyX. While I might try the former, I'm surely not going to test the latter. – egreg Jul 14 '14 at 21:05
  • LyX has nothing to do with this. I was just explaining my lack of familiarity with technical LaTeX stuff. – jaia Jul 14 '14 at 21:06
  • Just tried it out in TeX Studio and that doesn't work either, so it's not a QTikZ problem.The first error is Package pgfbasematrix Error: Single ampersand used with wrong catcode & A \arrow{dr}{g} \\. – jaia Jul 14 '14 at 21:23
  • 2
    @jaia I don't know what to say; what latest version of TeX Live are you running? If you're on Ubuntu, it's not the latest version, I'm afraid. Anyway, try with {} before the first & – egreg Jul 14 '14 at 21:30
  • That works, thanks! BTW, it's TeXLive version 2013.20140215-1. – jaia Jul 14 '14 at 21:37
  • In my humble opinion, it is easier for a newcomer to start by reading your update and if he is interested in the history, he will read it afterwards. Seen like that, it seems better to me that your update appears first and not last on your answer. – AndréC Jul 28 '20 at 11:03
  • 1
    @AndréC You're right. – egreg Jul 28 '20 at 11:12