Draw a commutative diagram - compiling error
You have a matrix of math nodes
, so the content of the matrix is already set in math mode, and adding the $
confuses things. Remove all the $
from the nodes in the matrix
, and things work fine.
\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{chemformula}
\usepackage{siunitx}
\usepackage{url}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em] {
\ch{H2O_s}\SI{-20}{\celsius} & \ch{H2O_l}\SI{50}{\celsius} \\
\ch{H2O_s}\SI{-0}{\celsius} & \ch{H2O_l}\SI{-0}{\celsius} \\};
\path[-stealth]
(m-1-1) edge node [left] {$Q_1$} (m-2-1)
edge node [below] {$Q_T$} (m-1-2)
(m-2-1.east|-m-2-2) edge node [below] {$Q_2$} node [above] {$\exists$} (m-2-2)
(m-1-2) edge node [right] {$Q_3$} (m-2-2)
edge [dashed,-] (m-2-1);
\end{tikzpicture}
\end{document}
I would use tikz-cd
which has a simpler syntax.
\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{chemformula,siunitx}
\usepackage{tikz-cd}
\usetikzlibrary{babel}
\begin{document}
\begin{tikzcd}
\ch{H2O_s}\SI{-20}{\celsius}
\arrow[r,"Q_T"]
\arrow[d,swap,"Q_1"]
&
\ch{H2O_l}\SI{50}{\celsius} \arrow[d,"Q_3"]
\\
\ch{H2O_s}\SI{-0}{\celsius}
\arrow[r,"\exists","Q_2" swap]
\arrow[ur,dashed,-]
&
\ch{H2O_l}\SI{-0}{\celsius}
\end{tikzcd}
\end{document}
\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
H_2O_s-20^{\circ}\, C \arrow[d, "Q_1"'] \arrow[rr, "Q_T"'] & & H_2O_150^{\circ}\, C \arrow[d] \\
H_2O_s 0^{\circ}\, C \arrow[rru, no head, dashed] \arrow[rr,"\exists","Q_2" swap] & & H_2O_1 0^{\circ}\, C
\end{tikzcd}
\end{document}