[Tex/LaTex] Align and boxed don’t work together

alignmiktex

When I try to input:

\begin{eqnarray*}
w(t) &=& \frac{1}{2}Cv^2(t)\\
\boxed{w(t) &=& \frac{1}{2}C \frac{q(t)^2}{C^2}}\\
w(t) &=& \frac{1}{2}\frac{q(t)^2}{C}\\
w(t) &=& \frac{1}{2}Cv^2(t)\\
\end{eqnarray*}

I get an error. The following code works but the box is way of to the left… (I didn't use &=& on the boxed equation this time.)

\begin{eqnarray*}
w(t) &=& \frac{1}{2}Cv^2(t)\\
\boxed{w(t) = \frac{1}{2}C \frac{q(t)^2}{C^2}}\\
w(t) &=& \frac{1}{2}\frac{q(t)^2}{C}\\
w(t) &=& \frac{1}{2}Cv^2(t)\\
\end{eqnarray*}

Are there any ways to fix this issue?

Best Answer

Why no use \Aboxed command of the package mathtools? inside of an align* environment

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
w(t) &= \frac{1}{2}Cv^2(t)\\
\Aboxed{w(t) &= \frac{1}{2}C \frac{q(t)^2}{C^2}}\\
w(t) &= \frac{1}{2}\frac{q(t)^2}{C}\\
w(t) &= \frac{1}{2}Cv^2(t)\\
\end{align*}
\end{document}

enter image description here

Related Question