绘制交换图-编译错误

绘制交换图-编译错误

我见过这个帖子用于编写交换图,出于某种chemistry目的需要。尝试时 latex 返回错误。我不明白发生了什么。

下面有一个平均能量损失

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage{chemformula}

\usepackage{siunitx}
\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}

答案1

您有一个matrix of math nodes,因此矩阵的内容已在数学模式中设置,添加 会使事情变得混乱。从 中的节点中$删除所有,一切正常。$matrix

在此处输入图片描述

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

答案2

我会使用tikz-cd语法更简单的。

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

在此处输入图片描述

答案3

在此处输入图片描述

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

相关内容