LaTeX – Why \mbox Does Not Draw a Box Inside align*

alignboxesmath-modemathtoolsmhchem

\mbox doesn't work inside align*:

\begin{document}
\usepackage{mhchem}

    \begin{align*} 
    \ce{K_w} &= \ce{[H3O+][OH^-]} \\
    -\log \ce{K_w} &= -\log ( \ce{[H3O+][OH^-]} ) \\
    -\log \ce{K_w} &= - ( \log \ce{[H3O+]} + \log \ce{[OH^-]} )  & \text{(Using log law for RHS.)}\\
    -\log \ce{K_w} &= -  \log \ce{[H3O+]} - \log \ce{[OH^-]} \\
    -\log \ce{K_w} &= -  \log \ce{[H3O+]} + - \log \ce{[OH^-]} \\
    \mbox{ \ce{pK_w} &= \ce{pH} + \ce{pOH} }\\
    \end{align*}

\end{document}

Best Answer

Perhaps you are trying to place a box around the last equation. One way to do that is to use Aboxed from the mathtools package:

\documentclass{article}
\usepackage{mathtools}
\usepackage{mhchem}
\begin{document}
    \begin{align*} 
    \ce{K_w} &= \ce{[H3O+][OH^-]} \\
    -\log \ce{K_w} &= -\log ( \ce{[H3O+][OH^-]} ) \\
    -\log \ce{K_w} &= - ( \log \ce{[H3O+]} + \log \ce{[OH^-]} )  & \text{(Using log law for RHS.)}\\
    -\log \ce{K_w} &= -  \log \ce{[H3O+]} - \log \ce{[OH^-]} \\
    -\log \ce{K_w} &= -  \log \ce{[H3O+]} + - \log \ce{[OH^-]} \\
    \Aboxed{ \ce{pK_w} &= \ce{pH} + \ce{pOH} }
    \end{align*}
\end{document}

enter image description here

While it is true that the descriptions of mbox tell you that it creates a box just wide enough to hold the text, this is not a box that gets drawn. It is a virtual "box" in the TeX sense that does not get split across lines.

Related Question