8

Newcomers wanting to use TikZ to create commutative diagrams face a varied (non-uniform) approach. I found this simple method to create a commutative diagram:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}

$$\begin{tikzpicture}[node distance=2cm, auto]
  \node (C) {$C$};
  \node (P) [below of=C] {$\prod_{i \in I} A_i$};
  \node (Ai) [right of=P] {$A_i$};
  \draw[->] (C) to node {$f_i$} (Ai);
  \draw[->, dashed] (C) to node [swap] {$\langle f_i \rangle_{i \in I}$} (P);
  \draw[->] (P) to node [swap] {$\pi_i$} (Ai);
\end{tikzpicture}$$

\end{document}

Which produces a neat commutative diagram: Diagram from code above

I wished to adapt this for my own commutative diagram. The code is as below:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}

$$\begin{tikzpicture}[node distance=2cm, auto]
  \node (V) {$V$};
  \node (FAI) [right of= V] {$FAI(V)$};
  \node (CL) [below of= FAI] {$CL(V,q)$};
  \draw[->] (V) to node (FAI);
  \draw[->, dashed] (FAI) to node (CL);
  \draw[->] (V) to node (CL);
\end{tikzpicture}$$

\end{document}

However, my diagram produces the compile error: "Package tikz Error: (, +, coordinate, pic, or node expected."

Reading on TeX, I have noticed users recommend alternative methods to draw commutative diagrams.

  1. What are current best practices (best packages to use, etc.)
  2. How do I use these best practise methods to accomplish my (simple) commutative diagram?
3
  • 2
    Why don't use just use tikz-cd instead of doing it by hand? Regarding your code, I don't recall ever seeing to node (..) before. I'd probably just use -- instead. Also never use $$...$$, it is not LaTeX.
    – daleif
    Feb 8, 2018 at 10:59
  • @daleif kind user preceded me by a minute. In fact I voted for your comment.
    – Sebastiano
    Feb 8, 2018 at 11:09

2 Answers 2

10

Here there is my version with tikz-cd. It is very easy to create simple and complex commutative diagrams.

Advice: do not worry about the background because It does not appear. Your initial code it is into this link.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
V \arrow[r] \arrow[rdd] & FAI(V) \arrow[dd, dotted] \\
 &  \\
 & CL(V,q)
\end{tikzcd}

\end{document}

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
C \arrow[d, "\langle f_i \rangle_{i \in I}"', dotted] \arrow[rd, "f_i"] &  \\
\prod_{i \in I} A_i \arrow[r, "\pi_i"'] & A_i
\end{tikzcd}
\end{document}
2
  • just wondering, where does that in the background in the images come from? and what is up with the "' in the last code example?
    – daleif
    Feb 8, 2018 at 11:24
  • 1
    It is to align the labels on the left and bottom.
    – Sebastiano
    Feb 8, 2018 at 11:30
7

Your code was almost correct, you just forgot the text label of the node.

Yours was like this:

\draw[->] (V) to node (FAI);

but it must be like this:

\draw[->] (V) to node {} (FAI);

or like this: (thanks @PaulGaborit)

\draw[->] (V) to (FAI);

I made three of these corrections.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}

$$\begin{tikzpicture}[node distance=2cm, auto]
  \node (V) {$V$};
  \node (FAI) [right of= V] {$FAI(V)$};
  \node (CL) [below of= FAI] {$CL(V,q)$};
  \draw[->] (V) to (FAI);% corrected here
  \draw[->, dashed] (FAI) to (CL);% here
  \draw[->] (V) to (CL);% and here
\end{tikzpicture}$$

\end{document}
2
  • 4
    It would be more appropriate to delete all empty nodes (node {}). Feb 8, 2018 at 11:05
  • Good work. +1 for your answer.
    – Sebastiano
    Feb 8, 2018 at 11:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .