6

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}
4
  • 2
    Does this answer your question? How to draw commutative diagrams? Dec 17, 2021 at 19:25
  • @JasperHabicht Why are you closing all the questions about tikz-cd? Even if they already have answers?
    – CarLaTeX
    Dec 17, 2021 at 20:17
  • @CarLaTeX I thought that they are very similar to each other. Some answers are even alike. But you are right, I should probably review my own close votes again ... Dec 17, 2021 at 20:28
  • @JasperHabicht Thank you!
    – CarLaTeX
    Dec 17, 2021 at 20:34

1 Answer 1

12

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

11
  • 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, 2014 at 20:51
  • @jaia Hmm, are you using that inside the argument to a command? What TeX distribution are you using?
    – egreg
    Jul 14, 2014 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, 2014 at 21:02
  • 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, 2014 at 21:30
  • 1
    @AndréC You're right.
    – egreg
    Jul 28, 2020 at 11:12

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