# Aligning labelled reactions in mhchem

Okay, i have asked this question a long time ago before, but i never got it solved, so i will try my luck again.

I have the following code.

\documentclass{report}

\usepackage[version=3]{mhchem}  %kemiske ligninger

\makeatletter
\newcounter{reaction}
\renewcommand\thereaction{R\,\thechapter.\arabic{reaction}}
\newcommand\reactiontag%
{\refstepcounter{reaction}\tag{\thereaction}}
\newcommand\reaction@[2][]%
{$$\ce{#2}% \ifx\@empty#1\@empty\else\label{#1}\fi% \reactiontag$$}
\newcommand\reaction@nonumber[1]%
{\begin{equation*}\ce{#1}\end{equation*}}
\newcommand\reaction%
{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother

\begin{document}

\reaction{CH4 + O2 -> CO2 + 2H2O}\\
\reaction{C2H6 + O2 -> 2CO2 + 3H2O}\\
\reaction{C3H8 + O2 -> 4CO2 +5H2O}\\
\reaction{C4H10 + O2 -> 3CO2 + 4H2O}

\end{document}

And i want to align the equations in a nice way. But align environment and anything else i try doesnt work. I hope you can help.

Sincerely Mikkel.

• Use package chemmacros. Set option formula=mhchem. Load module reactions. Renew the reaction's tagform. Use the reactions environment for typesetting the reactions. – clemens Apr 21 '16 at 14:05
• @clemens7 - Can you provide an examlpe if it's not too much trouble? I'm on my first semester of using LaTeX and i've still got much to learn. – Mikkel Miqlliot Lehmann Apr 21 '16 at 14:14
• I'll post something later today. As it turns out for having the reaction counter within chapters I need to update chemmacros first, though. – clemens Apr 23 '16 at 8:29

\documentclass{report}

\usepackage[version=3]{mhchem}

\makeatletter
\newcounter{reaction}
\renewcommand\thereaction{R\,\thechapter.\arabic{reaction}}
\newcommand\reactiontag%
{\refstepcounter{reaction}\tag{\thereaction}}
\newcommand\areaction[2][]%
{\ce{#2}%
\ifx\@empty#1\@empty\else\label{#1}\fi%
\reactiontag}
\makeatother

\begin{document}

\begin{alignat}{3}
\areaction{CH4   &+ O2 ->& CO2  &+ 2H2O}\\
\areaction{C2H6  &+ O2 ->& 2CO2 &+ 3H2O}\\
\areaction{C3H8  &+ O2 ->& 4CO2 &+ 5H2O}\\
\areaction{C4H10 &+ O2 ->& 3CO2 &+ 4H2O}
\end{alignat}

\end{document}
• For some reason this doesnt seem to be able to compile. – Mikkel Miqlliot Lehmann Apr 21 '16 at 17:04
• @MikkelMiqlliotLehmann works for me. Maybe you need to update your distribution? – clemens Apr 23 '16 at 8:30
• @clemens I'm up to date using TexStudio, using the code above just makes the program compile till \infty. – Mikkel Miqlliot Lehmann Apr 25 '16 at 8:11

With an up to date version of chemmacros:

\documentclass{report}
\usepackage{chemmacros}[2016/05/04]
\usepackage[version=4]{mhchem}

\chemsetup{
formula = mhchem ,
modules  = {reactions}
}

\renewcommand\thereaction{R\,\thechapter.\arabic{reaction}}
\renewtagform{reaction}{(}{)}
\NewChemReaction{reactionsat}[1]{alignat}

\begin{document}

\begin{reactions}
CH4 + O2   &->  CO2 + 2H2O \\
C2H6 + O2  &-> 2CO2 + 3H2O \\
C3H8 + O2  &-> 4CO2 + 5H2O \\
C4H10 + O2 &-> 3CO2 + 4H2O
\end{reactions}

\begin{reactionsat}{3}
CH4   &+ O2 ->&  CO2 &+ 2H2O \\
C2H6  &+ O2 ->& 2CO2 &+ 3H2O \\
C3H8  &+ O2 ->& 4CO2 &+ 5H2O \\
C4H10 &+ O2 ->& 3CO2 &+ 4H2O
\end{reactionsat}

\end{document}