# tikz Commutative Diagrams - Compiling and Best Practice

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:

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?
• 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 '18 at 10:59
• @daleif kind user preceded me by a minute. In fact I voted for your comment. – Sebastiano Feb 8 '18 at 11:09
• – Ignasi Feb 8 '18 at 16:21

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

\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}


\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}

• 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 '18 at 11:24
• It is to align the labels on the left and bottom. – Sebastiano Feb 8 '18 at 11:30

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.

\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}

• It would be more appropriate to delete all empty nodes (node {}). – Paul Gaborit Feb 8 '18 at 11:05
• Good work. +1 for your answer. – Sebastiano Feb 8 '18 at 11:10