4

I want to put a box around the final two lines in this

\begin{equation}
\begin{split}
\left\langle\vec{u}\right\rangle&=\frac{1}{4}\Re\left(\epsilon_0\vec{\overset{\sim}{E}}\cdot\vec{\overset{\sim}{E}}^*+\frac{1}{\mu_0}\vec{\overset{\sim}{B}}\cdot\vec{\overset{\sim}{B}}^*\right) \\
&=\frac{1}{4}\left[\epsilon_0\left(\frac{\pi\omega B_0}{\left(\frac{\omega}{c}\right)^2-k^2}\right)^2\left[\left(\frac{n}{b}\right)^2\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)+\left(\frac{m}{a}\right)^2\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right]\right. \\
&\qquad+\frac{1}{\mu_0}\left(\frac{\pi kB_0}{\left(\frac{\omega}{c}\right)^2-k^2}\right)^2\left[\left(\frac{m}{a}\right)^2\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)+\left(\frac{n}{b}\right)^2\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)\right. \\
&\qquad\qquad\left.\left(\frac{\left(\frac{\omega}{c}\right)^2-k^2}{\pi k}\right)\cos^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right] \\

%Box starting here

&=\left(\frac{\pi B_0}{2\left[\left(\frac{\omega}{c}\right)^2-k^2\right]}\right)^2\left[\left(\epsilon_0\omega+\frac{k}{\mu_0}\right)\left[\left(\frac{n}{b}\right)^2\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)\right.\right. \\
&\qquad\left.\left.+\left(\frac{m}{a}\right)^2\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right]+\left(\frac{\left(\frac{\omega}{c}\right)^2-k^2}{\pi\mu_0k}\right)\cos^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right]

%and ending here

\end{split}
\end{equation}

First block of code output I want it to pretty much look like this

\begin{equation}
\begin{split}
\left\langle\vec{S}\right\rangle&=\frac{1}{2\mu_0}\Re\left(\vec{\overset{\sim}{E}}\times\vec{\overset{\sim}{B}}^*\right) \\
&=\frac{1}{2\mu_0}\Re\left(\frac{i\pi B_0}{\left(\frac{\omega}{c}\right)^2-k^2}\left[\left\langle\frac{-n\omega}{b}\left[\cos\left(\frac{m\pi}{a}x\right)\sin\left(\frac{n\pi}{b}y\right)\right],\frac{m\omega}{a}\left[\sin\left(\frac{m\pi}{a}x\right)\cos\left(\frac{n\pi}{b}y\right)\right],0\right\rangle\right.\right. \\
&\qquad\times\left\langle\frac{mk}{a}\left[\sin\left(\frac{m\pi}{a}x\right)\cos\left(\frac{n\pi}{b}y\right)\right],\frac{nk}{b}\left[\cos\left(\frac{m\pi}{a}x\right)\sin\left(\frac{n\pi}{b}y\right)\right],\right. \\
&\qquad\qquad\left.\left.\left.\frac{-i\left[\left(\frac{\omega}{c}\right)^2-k^2\right]}{\pi}\cos\left(\frac{m\pi}{a}x\right)\cos\left(\frac{n\pi}{b}y\right)\right\rangle\right]\right) \\
&=\frac{1}{2\mu_0}\Re\left(\frac{i\pi B_0}{\left(\frac{\omega}{c}\right)^2-k^2}\left\langle\frac{-im\omega\left[\left(\frac{\omega}{c}\right)^2-k^2\right]}{\pi a}\sin\left(\frac{m\pi}{a}x\right)\cos\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right),\right.\right. \\
&\qquad\frac{in\omega\left[\left(\frac{\omega}{c}\right)^2-k^2\right]}{\pi b}\cos^2\left(\frac{m\pi}{a}x\right)\sin\left(\frac{n\pi}{b}y\right)\cos\left(\frac{n\pi}{b}y\right), \frac{-n^2\omega k}{b^2}\left[\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)\right] \\
&\qquad\qquad\left.\left.-\frac{m^2\omega k}{a^2}\left[\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right]\right\rangle\right) \\
&\fbox{$=\frac{\omega B_0}{2\mu_0}\left\langle\frac{m}{a}\sin\left(\frac{m\pi}{a}x\right)\cos\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right),\frac{n}{b}\cos^2\left(\frac{m\pi}{a}x\right)\sin\left(\frac{n\pi}{b}y\right)\cos\left(\frac{n\pi}{b}y\right),0\right\rangle$}
\end{split}
\end{equation}

Second block of code output I've tried using \fbox, but I cannot seem to get it to span multiple lines keeping my paragraphing and tabs. Also sorry for the messy code!

4
  • 2
    Welcome to TeX SX! Do you really want the box to include the = signs?
    – Bernard
    Commented Oct 17, 2020 at 18:31
  • Yeah I kind of like how it looks because sometimes I'll put the \approx in the box to show that the answer is approximate and not exact. Commented Oct 17, 2020 at 18:38
  • Off-topic: Do please write \widetilde{E} instead of \overset{\sim}{E}.
    – Mico
    Commented Oct 17, 2020 at 19:15
  • Aside: Your equation would appear to be missing a \right] (or \biggr] directive at the end of the third row.
    – Mico
    Commented Oct 17, 2020 at 19:24

2 Answers 2

4

The amsmath package provides a macro called \boxed for just this purposes. Note that I encased an aligned environment inside the \boxed directive. And I also replaced all instances of \left(\frac{\omega}{c}\right) with (\omega/c) to achieve a more compact appearance of the formulas.

In the following solution, the = symbol is not inside the box. If it has to be inside the box, you'll need to replace

%Box starting here
&=\boxed{\begin{aligned}[t]
&\biggl(\frac{\pi B_0}{2\left[(\omega/c)^2-k^2\right]}\biggr)^{\!2}

with

%Box starting here
&\boxed{\begin{aligned}
&=\biggl(\frac{\pi B_0}{2\left[(\omega/c)^2-k^2\right]}\biggr)^{\!2}

in the code given below.

enter image description here

\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters appropriately
\usepackage{amsmath}
\usepackage{mleftright} % for tightly-spaced \left...\right constructs
\mleftright

\begin{document}
\begin{equation}
\begin{split}
\langle\vec{u}\mkern1.5mu\rangle
&=\frac{1}{4}\Re\Bigl( \epsilon_0\vec{\widetilde{E}}\cdot\vec{\widetilde{E}}^*
 +\frac{1}{\mu_0}\vec{\widetilde{B}}\cdot\vec{\widetilde{B}}^* \Bigr) \\
&=\frac{1}{4}
 \Biggl[
 \epsilon_0
 \left(\frac{\pi\omega B_0}{(\omega/c)^2-k^2}\right)^{\!2}
 \left[\left(\frac{n}{b}\right)^2\cos^2
 \left(\frac{m\pi}{a}x\right)\sin^2
 \left(\frac{n\pi}{b}y\right)
+\left(\frac{m}{a}\right)^2\sin^2
 \left(\frac{m\pi}{a}x\right)\cos^2
 \left(\frac{n\pi}{b}y\right)\right] \\
&\qquad+\frac{1}{\mu_0}
 \left(\frac{\pi kB_0}{(\omega/c)^2-k^2}\right)^{\!2}
 \left[\left(\frac{m}{a}\right)^2\sin^2
 \left(\frac{m\pi}{a}x\right)\cos^2
 \left(\frac{n\pi}{b}y\right)
+\left(\frac{n}{b}\right)^2\cos^2
 \left(\frac{m\pi}{a}x\right)\sin^2
 \left(\frac{n\pi}{b}y\right)\right. \\
&\qquad\qquad
 \left(\frac{(\omega/c)^2-k^2}{\pi k}\right)\cos^2 
 \left(\frac{m\pi}{a}x\right)\cos^2
 \left(\frac{n\pi}{b}y\right) 
 \Biggr] \\
%Box starting here
&=\boxed{\begin{aligned}[t]
&\biggl(\frac{\pi B_0}{2\left[(\omega/c)^2-k^2\right]}\biggr)^{\!2}
 \Biggl[
 \left(\epsilon_0\omega+\frac{k}{\mu_0}\right)
 \biggl[\left(\frac{n}{b}\right)^2\cos^2
 \left(\frac{m\pi}{a}x\right)\sin^2
 \left(\frac{n\pi}{b}y\right) \\
&\qquad+\left(\frac{m}{a}\right)^2\sin^2
 \left(\frac{m\pi}{a}x\right)\cos^2
 \left(\frac{n\pi}{b}y\right)\biggr]
+\left(\frac{(\omega/c)^2-k^2}{\pi\mu_0k}\right)\cos^2
 \left(\frac{m\pi}{a}x\right)\cos^2
 \left(\frac{n\pi}{b}y\right)
 \Biggr] 
\end{aligned}}
%and ending here
\end{split}
\end{equation}
\end{document}
3
  • 1
    Thanks so much man this was throwing me for a loop. Commented Oct 17, 2020 at 19:06
  • @JaredanDurbin - The convenient aspect of \boxed is that its argument is in the same math mode as what's around it. One could cook up an \fbox-based solution, but then one would also have to take care of switching back into the appropriate math mode inside the \fbox. For instance, in the example code you posted, you used $ instead of $\displaystyle after \fbox{ and hence (probably inadvertently) used inline math mode instead of display math mode.
    – Mico
    Commented Oct 17, 2020 at 19:23
  • 1
    I realized that when I was searching for answers to this. I just started using Latex this semester since I wanted to make my homeworks look nicer, and would need to use it in grad school. Commented Oct 17, 2020 at 19:34
1

The \Aboxed command from mathtools alows for including the alignment point in a framebox. To enclose several lines I use the multlined environment from the same package, and aligned for the lines above:

\documentclass{article}
\usepackage{geometry} 
\usepackage{mathtools}

\begin{document}

\begin{equation}
\begin{split}
\left\langle\vec{u}\right\rangle&=\frac{1}{4}\Re\left(\epsilon_0\vec{\overset{\sim}{E}}\cdot\vec{\overset{\sim}{E}}^*+\frac{1}{\mu_0}\vec{\overset{\sim}{B}}\cdot\vec{\overset{\sim}{B}}^*\right) \\
&=\begin{alignedat}[t]{2} \frac{1}{4}\Biggl[& \epsilon_0\left(\frac{\pi\omega B_0}{\left(\frac{\omega}{c}\right)^2-k^2}\right)^{\mkern-5mu 2} \left[\left(\frac{n}{b}\right)^2\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)+\left(\frac{m}{a}\right)^2\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right] & & \\
 & +\frac{1}{\mu_0}\left(\frac{\pi kB_0}{\left(\frac{\omega}{c}\right)^2 - k^2}\right)^{\mkern-5mu 2} \biggl[\left(\frac{m}{a}\right)^2\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\\%
 & & \mathllap{+\left(\frac{n}{b}\right)^2\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)
\left(\frac{\left(\frac{\omega}{c}\right)^2-k^2}{\pi k}\right)\cos^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\Biggr]} &
\end{alignedat}\\
%Box starting here
\Aboxed{&=\begin{multlined}[t] \left(\frac{\pi B_0}{2\left[\left(\frac{\omega}{c}\right)^2-k^2\right]}\right)^{\mkern-5mu 2} \left[\left(\epsilon_0\omega+\frac{k}{\mu_0}\right)\left[\left(\frac{n}{b}\right)^2\cos^2\left(\frac{m\pi}{a}x\right)\sin^2\left(\frac{n\pi}{b}y\right)\right.\right. \\
\left.\left.+\left(\frac{m}{a}\right)^2\sin^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right]+\left(\frac{\left(\frac{\omega}{c}\right)^2-k^2}{\pi\mu_0k}\right)\cos^2\left(\frac{m\pi}{a}x\right)\cos^2\left(\frac{n\pi}{b}y\right)\right]
\end{multlined}}
%and ending here
\end{split}
\end{equation}

 \end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .