使用 tikz 和 mhchem 在曲线上写化学式

使用 tikz 和 mhchem 在曲线上写化学式
\documentclass{article}
\usepackage{tikz}
\usepackage[version=4]{mhchem}
\usetikzlibrary{decorations.text}
\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=rectangle,rounded corners,draw] 
{\textcolor{blue}{\ce{R-C#N + H2O}}}; 
\node (Mid) at (0,0) [shape=circle,draw, fill=gray]
{\textcolor{green}{\Huge ?}};
\node (Two) at (3,0) [shape=rectangle,rounded corners,draw] {\textcolor{red}{\ce{R-C(OH)=NH}}};
\draw [>->>, ultra thick, cyan] (One) to [bend right=45]  (Two);
\pgftransformyshift{-.65cm}
\draw [decoration={text along path,
       text={On ice-grains: catalysed by hydronium ion}, text align={center}},decorate]  (-3,0) to [bend right=45]  (3,0);
\draw [>->>, ultra thick, dashed, magenta] (One) to  [bend left=45] (Two);
\pgftransformreset
\pgftransformyshift{.5cm}
\draw[decoration={text along path,
      text={Gas-phase},text align={center}},decorate] (-3,0) to [bend left=45]  (3,0);
\node (mental) at (0,1.75) {};
\node (non-mental) at (0,-1.75) {};
\end{tikzpicture}
\end{document}

我想用 替换“水合氢离子” \ce{H3O+}

答案1

改编

  • text要在选项内插入命令或decoration使用花括号括起来:text={On ice-grains: catalysed by {\ce{H3O+}}

代码

\documentclass{article}
\usepackage{tikz}
\usepackage[version=4]{mhchem}
\usetikzlibrary{decorations.text}
\begin{document}

\begin{tikzpicture}
\node (One) at (-3,0) [shape=rectangle,rounded corners,draw] 
{\textcolor{blue}{\ce{R-C#N + H2O}}}; 
\node (Mid) at (0,0) [shape=circle,draw, fill=gray]
{\textcolor{green}{\Huge ?}};
\node (Two) at (3,0) [shape=rectangle,rounded corners,draw] {\textcolor{red}{\ce{R-C(OH)=NH}}};
\draw [>->>, ultra thick, cyan] (One) to [bend right=45]  (Two);
\pgftransformyshift{-.65cm}
\draw [decoration={text along path,
       text={On ice-grains: catalysed by {\ce{H3O+}}}, text align={center}},decorate]  (-3,0) to [bend right=45]  (3,0);
\draw [>->>, ultra thick, dashed, magenta] (One) to  [bend left=45] (Two);
\pgftransformreset
\pgftransformyshift{.5cm}
\draw[decoration={text along path,
      text={Gas-phase},text align={center}},decorate] (-3,0) to [bend left=45]  (3,0);
\node (mental) at (0,1.75) {};
\node (non-mental) at (0,-1.75) {};
\end{tikzpicture}
\end{document}

结果

在此处输入图片描述

相关内容