[Tex/LaTex] tikz Commutative Diagrams – Compiling and Best Practice

commutative-diagramstikz-pgf

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?

Best Answer

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}