LaTeX forum ⇒ Math & Sciencebox around just one equation inside align

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
kwicky
Posts: 2
Joined: Sun Mar 21, 2010 1:53 pm

box around just one equation inside align

Postby kwicky » Sun Mar 21, 2010 1:59 pm

Hi,
I am using "\begin{align}..." to align two equations. I would like to put a box around the second equation only. However, "\boxed{...}" does not seem to work if the alignment character "&" is inside the "{}".
Any advice?

Thanks a lot,
Kai

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Postby daleif » Sun Mar 21, 2010 11:32 pm

As you have seen you cannot directly, but we can cheat a little (in the example memoir is not important, it is jut my standard class in emacs)

\documentclass{memoir}
\usepackage{calc,amsmath}
\newlength\dlf
\newcommand\alignedbox[2]{
  % #1 = before alignment
  % #2 = after alignment
  &
  \begingroup
  \settowidth\dlf{$\displaystyle #1$}
  \addtolength\dlf{\fboxsep+\fboxrule}
  \hspace{-\dlf}
  \boxed{#1 #2}
  \endgroup
}
\begin{document}

\begin{align*}
  f(x) &= a \\
  \alignedbox{g(x)}{=5}
\end{align*}
\end{document}


It is the same kind of trick \MoveEqLeft from mathtools make use of

kwicky
Posts: 2
Joined: Sun Mar 21, 2010 1:53 pm

Postby kwicky » Mon Mar 22, 2010 10:07 am

Daleif,

Brilliant, works perfectly!
Thanks a lot,

Kai


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 9 guests