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

Link:
BBcode:
HTML:
Hide post links
Show post links

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)

  1. \documentclass{memoir}
  2. \usepackage{calc,amsmath}
  3. \newlength\dlf
  4. \newcommand\alignedbox[2]{
  5. % #1 = before alignment
  6. % #2 = after alignment
  7. &
  8. \begingroup
  9. \settowidth\dlf{$\displaystyle #1$}
  10. \addtolength\dlf{\fboxsep+\fboxrule}
  11. \hspace{-\dlf}
  12. \boxed{#1 #2}
  13. \endgroup
  14. }
  15. \begin{document}
  16.  
  17. \begin{align*}
  18. f(x) &= a \\
  19. \alignedbox{g(x)}{=5}
  20. \end{align*}
  21. \end{document}


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

Link:
BBcode:
HTML:
Hide post links
Show post links

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

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 5 guests