4

I’m trying to have a first equation split on two lines, first one being left aligned, second one right aligned, equation number centered for those two lines, and then a second (numbered) equation that would align at one particular point with a symbol from the second line.

I’ve looked a bit around but couldn’t find a non-manual spacing solution for this case.

Here is what the code would look like

\documentclass{article}

\usepackage{mathtools}
\usepackage{mhchem}

\begin{document}

\begin{align}
    \begin{multlined}[.88\linewidth]
        \ce{2CaCO3 + 5C + 2CaC2 + 4H2O + 2Ca(OH)2 + 2CO2} \\
        \ce{&-> 2CaC2 + 3CO2 + 2Ca(OH)2 + 2C2H2 + 2CaCO3 + 2H2O}
    \end{multlined}\\
    \ce{5C + 2H2O &-> CO2 + 2C2H2}.
\end{align}

\end{document}

excepted of course this does not work. If it did, it should look a bit like this:

2 CaCO₃ + 5 C + 2 CaC₂ + 4 H₂O + 2 Ca(OH)₂ + 2 CO₂
                         ——⟶ 2 CaC₂ + 3 CO₂ + 2 Ca(OH)₂ + 2 C₂H₂ + 2 CaCO₃ + 2 H₂O
             5 C + 2 H₂O ——⟶ CO₂ + 2 C₂H₂

with one equation number for the first two lines, vertically centered, and one equation number for the last line.

This code also provide a manual solution giving roughly the result I expect

\documentclass{article}

\usepackage[margin=2cm]{geometry}
\usepackage{mathtools}
\usepackage{mhchem}

\begin{document}

\begin{align}
    \begin{split}
        \ce{2CaCO3 + 5C + 2CaC2 + 4H2O& + 2Ca(OH)2 + 2CO2} \\                                                                                                                                                                                                                  
        \ce{&-> 2CaC2 + 3CO2 + 2Ca(OH)2 + 2C2H2 + 2CaCO3 + 2H2O}
    \end{split}\\
    \ce{5C + 2H2O &-> CO2 + 2C2H2}.
\end{align}

\end{document}

working manual example But it requires finding manually where to put the first & so I’m looking for a more general solution.

I would accept a solution using other environments as long as they match the requirements stated in my first paragraph (e.g. something that left/right align the first equation while using a split for instance).

6
  • Would you mind adding a sketch? I do not seem to understand what the desired output is. Oct 30, 2021 at 17:59
  • @JoshuaGonzález Done, also changed a bit the code to avoid some possible confusions.
    – Archange
    Oct 30, 2021 at 18:44
  • @Archange: Something like this?
    – Werner
    Oct 30, 2021 at 20:03
  • @Werner Not really, because I really need the first line to be flushed left and the second one flushed right (here I suspect you just aligned the first line at its right). The reason is that the real equation is longer than one line, hence the split using multlined.
    – Archange
    Oct 30, 2021 at 20:06
  • 1
    @egreg Sorry, maybe I minified my example too much you are right. Edited to show actual equation (now the world knows that I do chemistry… while I had a reputation of being a pure physicist ^^).
    – Archange
    Oct 30, 2021 at 20:22

1 Answer 1

3

I'd do it with split. The first line is artificially made the same size as the part before the arrow in the last line.

\documentclass{article}
\usepackage{geometry}

\usepackage{mathtools}
\usepackage[version=4]{mhchem}

\begin{document}

\begin{align}
\begin{split}
\sbox0{\ce{5C + 2H2O}}
\makebox[\wd0][l]{\ce{2CaCO3 + 5C + 2CaC2 + 4H2O + 2Ca(OH)2 + 2CO2}} \\
\ce{&-> 2CaC2 + 3CO2 + 2Ca(OH)2 + 2C2H2 + 2CaCO3 + 2H2O}
\end{split}\\
\ce{5C + 2H2O &-> CO2 + 2C2H2}.
\end{align}

\end{document}

enter image description here

I loaded geometry because the reactions would not fit in the standard text width of article.

Here's how to move the first line to the left margin.

\documentclass{article}
\usepackage[margin=2cm,showframe]{geometry}

\usepackage{mathtools}
\usepackage[version=4]{mhchem}

\makeatletter
\def\column@width#1{\ifcase\@xp#1\maxcolumn@widths\fi}
\def\shift@{%
  \ifmeasuring@
    0pt
  \else
    \dimexpr(\displaywidth+\column@width{1}-\column@width{2})/2\relax
  \fi
}
\def\movetoleft#1{%
  &\makebox[0pt][l]{\hspace{-\shift@}#1}%
}
\makeatother

\begin{document}

\begin{align}
\begin{split}
\movetoleft{\ce{2CaCO3 + 5C + 2CaC2 + 4H2O + 2Ca(OH)2 + 2CO2}} \\
\ce{&-> 2CaC2 + 3CO2 + 2Ca(OH)2 + 2C2H2 + 2CaCO3 + 2H2O}
\end{split}\\
\ce{5C + 2H2O &-> CO2 + 2C2H2}.
\end{align}

\end{document}

enter image description here

6
  • It does not push the second line as right as I would like, but I guess this is because your \sbox makes it align left for the bottom line. So I would have to adjust this \sbox until it has the right size. At this point I could just much more simply align manually (by using a split too, and putting an & at a guessed/checked place in the first line).
    – Archange
    Oct 30, 2021 at 20:49
  • I’ve added my manual solution to my question and clarification that I’m looking for something general.
    – Archange
    Oct 30, 2021 at 21:04
  • 1
    @Archange Does the second version do what you want?
    – egreg
    Oct 30, 2021 at 21:56
  • It’s better, but the second line is not enough flushed to right.
    – Archange
    Oct 30, 2021 at 22:09
  • @Archange Then go forth and do it. I'll stop here. I see no reason for doing like that. And I'd not flush.
    – egreg
    Oct 30, 2021 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.