Chemmacros arrow in Tikz node

I want to use Chemmacros inside a tikz node but the arrow of the reaction is disturbed by the line before the node. My example work fine if I use mhchem (\ce{A -> B}) instead of chemmacros. My MWE

\documentclass[10pt,a4paper]{article}
\usepackage{chemmacros}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- ++(1,1)
node[anchor=west]{\ch{A -> B}};
\end{tikzpicture}
\end{document}


Look and the end of the chemmacros arrow.

• Not surprising since you are nesting tikzpictures. Please avoid putting chmemmacros into nodes of tikzpictures. – user121799 Aug 19 '18 at 15:42

I understand the problem. One solution:

\documentclass[10pt,a4paper]{article}
\usepackage{chemmacros}
\usepackage{tikz}
\begin{document}
\newsavebox{\mybox}
\sbox{\mybox}{%
\ch{2 H+ \aq{} + 2 e- -> H2 \gas}
}
\begin{tikzpicture}
\draw[->] (0,0) -- ++(1,1) node[anchor=west]
{\usebox{\mybox}};
\end{tikzpicture}
\end{document}


like is explain here nesting tikzpicture

• Yes, precisely. +1 Unfortunately your code in your question did not compile. Any chance that in more recent versions of chemmacros you need to do something in addition? Could you perhaps check that and, if it does not work with the updated version, append a solution for that case as well? Others with the same problem might find that useful... – user121799 Aug 19 '18 at 22:26

Is that ok, too?

\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0) -- ++(1,1)
node[anchor=west]{A \tikz[baseline=-.1cm]{\draw[>=stealth'](0,0)--+(.6,0)} B};
\end{tikzpicture}
\end{document}


• I want to use chemmacros for my chemistry lessons. For example I want to put inside the node: \ch{2 H+ \aq{} + 2 e^- -> H2 \gas} or something more complex. – jrivet Aug 19 '18 at 15:47
• @jrivet: As marmot already mentioned you sholdn't use chemmacros in TikZ-nodes. Try to write it "by hand". – current_user Aug 19 '18 at 15:48
• My example work fine if I use mhchem (\ce{A -> B}) instead of chemmacros. Can we get arround the difficulty? – jrivet Aug 19 '18 at 15:52
• @jrivet: If that does work (I didn't tried it since yet) that you can use it. But it's "safer" to do it by hand if there are any problems … – current_user Aug 19 '18 at 15:53
• @current_user What is the difference between using a tikzpicture environment in a node, and using its inline equivalent \tikz in a node? – Max Aug 19 '18 at 18:06