8

\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}
David Carlisle
  • 757,742
ptrcao
  • 6,603
  • \mbox should not span across the alignment operator & in the align (or align*) environment. So you need \mbox{...} &= \mbox{...}. Why do you want to do this anyway? – Werner Oct 02 '11 at 06:17
  • Unfortunately, it doesn't work. Even if it did, is there a less awkward solution than splitting up my box command? I want to do it to emphasize a particular result which should be remembered. I thought of using empheq but that seems pretty heavy-handed; I just want that one line boxed in the least obstrusive way possible as far as the code I have to add. – ptrcao Oct 02 '11 at 06:38
  • Unlike the operator p equilibrium constants such as Kw are simple variables and should simply be typeset as such, i.e., in math mode and in italics $K_w$. For reference see page 58 of IUPAC Green Book (third edition). – cgnieder May 24 '13 at 20:35

2 Answers2

15

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.

David Carlisle
  • 757,742
Peter Grill
  • 223,288
3

If you want the highlighting of the equation to be a bit more subtle, you can modify the \Aboxed command provided by the mathtools package. For instance, in the example below, the equation of interest is emphasized with a 15% black background (alternatives is also possible, of course):

\documentclass{article}
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage[version=3]{mhchem}% http://ctan.org/pkg/mhchem
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\@Aboxed}{\boxed{#1#2}}{\colorbox{black!15}{$#1#2$}}{}{}%
\makeatother
\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}

Modified \Aboxed

Modification of \Aboxed is performed using \patchcmd{<command>}{<search>}{<replace>}{<success>}{<failure>} (provided by the etoolbox package). Specifically, the \boxed{#1#2} command (that boxes the left- #1 and right-hand side #2 of the equation in align) is replaced with \colorbox{<color>}{$#1#2$} allowing for a coloured box. Colour choices is supported by means of xcolor.

Moriambar
  • 11,466
Werner
  • 603,163