# Box or [ around multiple lines inside align

I have the following code

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{alignat*}{4}
\begin{minipage}[h!]{0\linewidth}
\text{Let:} \end{minipage}
&& G_{\delta_r}^{\beta} &= \frac{n_1 s + n_0}{s^2 + d_1 s + d_0} = \frac{0.01956 s + 7.01}{s^2 + 0.802 s + 6.489} \\
&& step \left(G_{\delta_r}^{\beta}(s) \right) = \frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1}{s} \cdot \frac{n_1 s + n_0}{s^2 + d_1 s + d_0} \\
\\
% \left[
% \makebox[0\linewidth][s] {
%   \begin{dcases}
\makebox[0\linewidth][s]{Expanding with partial fractions:} \\
&& \frac{x_1}{s} + \frac{x_{21}s + x_{20}}{s^2 + d_1 s + d_0} &= \frac{1}{s} \cdot \frac{n_1 s + n_0}{s^2 + d_1 s + d_0} \\
\\
\makebox[0\linewidth][s]{Removing denominator:} \\
&& x_1(s^2 + d_1 s + d_0) + s(x_{21} s + x_{20}) &= n_1 s + n_0 \\
\\
\makebox[0\linewidth][s]{Has solutions:} \\
\makebox[0\linewidth][s]{
\begin{minipage}[h!]{0.3\linewidth} \centering
$x_{21} = \frac{-n_0}{d_0} = -1.08$ \end{minipage}
\begin{minipage}[h!]{0.3\linewidth} \centering
$x_1 = \frac{n_0}{d_0} = 1.08$ \end{minipage}
\begin{minipage}[h!]{0.3\linewidth} \centering
$x_{20} = n_1 - \frac{n_0 d_1}{d_0} = -0.847$ \end{minipage} }
% \end{dcases}
% }
\\
\begin{minipage}[h!]{0\linewidth}
\text{Hence:} \end{minipage}
&& \frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1.08}{s} - \frac{1.08s + 0.847}{s^2 + 0.8-2s + 6.489} \\
\\
\makebox[0\linewidth][s]{Completing the square:} \\
&& \frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1.08}{s} - \frac{1.08s + 0.847}{(s + 0.401)^2 + 6.328} \\
\makebox[0\linewidth][s]{Inverse Laplace:} \\
&& \mathcal{L}^{-1}\left\{ \frac{G_{\delta_r}^{\beta}(s)}{s} \right\} &=  1.08 - e^{-.401t} \left(1.08 \cos(t\sqrt{6.328}) + \frac{0.847}{\sqrt{6.328}} \sin(t\sqrt{6.328}) \right)
\end{alignat*}
\end{document}


Which produces:

I would like to put a box (or some kind of a bracket) like the one shown in the picture to denote "sub working out". The complications are that the box will need to span many lines of equations and many columns of the alignat environment.

I have tried many things including \makebox, \minipage, \bcases, \matrix

Any suggestions?

• You should look into some best practices for your actual code, but I would do some googling for tikzmark. That's what immediately comes to mind. – Sean Allred Apr 13 '14 at 6:16

An option using a \parbox inside a \fcolorbox inside a \makebox, and the whole construct inside \intertext; some changes to the original mark-up were done (in particular, the code was greatly simplified), but the original alignment of expressions before and after the box was preserved:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}

\begin{document}

Let:
\begin{align*}
G_{\delta_r}^{\beta} &= \frac{n_1 s + n_0}{s^2 + d_1 s + d_0} = \frac{0.01956 s + 7.01}{s^2 + 0.802 s + 6.489} \\
\text{step} \left(G_{\delta_r}^{\beta}(s) \right) = \frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1}{s} \cdot \frac{n_1 s + n_0}{s^2 + d_1 s + d_0}
\intertext{%
\makebox[\linewidth][c]{\fcolorbox{blue}{white}{\parbox{\linewidth}{%
Expanding with partial fractions:
$\frac{x_1}{s} + \frac{x_{21}s + x_{20}}{s^2 + d_1 s + d_0} = \frac{1}{s} \cdot \frac{n_1 s + n_0}{s^2 + d_1 s + d_0}$
Removing denominator:
$x_1(s^2 + d_1 s + d_0) + s(x_{21} s + x_{20}) = n_1 s + n_0$
Has solutions:
$x_{21} = \frac{-n_0}{d_0} = -1.08\qquad x_1 = \frac{n_0}{d_0} = 1.08\qquad x_{20} = n_1 - \frac{n_0 d_1}{d_0} = -0.847$
Hence:}}}
}
\frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1.08}{s} - \frac{1.08s + 0.847}{s^2 + 0.8-2s + 6.489} \\
\shortintertext{Completing the square:}
\frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1.08}{s} - \frac{1.08s + 0.847}{(s + 0.401)^2 + 6.328} \\
\shortintertext{Inverse Laplace:}
\mathcal{L}^{-1}\left\{ \frac{G_{\delta_r}^{\beta}(s)}{s} \right\} &=  1.08 - e^{-.401t} \left(1.08 \cos\alpha + \frac{0.847}{\sqrt{6.328}} \sin\alpha \right),
\end{align*}
where $\alpha=t\sqrt{6.328}$.

\end{document}


Another option would be to use the tikzmark library; the idea is to use \tikzmark to place marks at the appropriate locations and then to use those marks to draw the blue rectangle. Below I show this approach and also illustrate another option for the mark-up (of course, this approach will also work with the above approach or with any other variation):

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}

\begin{document}

Let:
\begin{align*}
G_{\delta_r}^{\beta} &= \frac{n_1 s + n_0}{s^2 + d_1 s + d_0} = \frac{0.01956 s + 7.01}{s^2 + 0.802 s + 6.489} \\
\text{step} \left(G_{\delta_r}^{\beta}(s) \right) = \frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1}{s} \cdot \frac{n_1 s + n_0}{s^2 + d_1 s + d_0}
\end{align*}
\tikzmark{start}Expanding with partial fractions:
$\frac{x_1}{s} + \frac{x_{21}s + x_{20}}{s^2 + d_1 s + d_0} = \frac{1}{s} \cdot \frac{n_1 s + n_0}{s^2 + d_1 s + d_0}$
Removing denominator:
$x_1(s^2 + d_1 s + d_0) + s(x_{21} s + x_{20}) = n_1 s + n_0$
Has solutions:
$x_{21} = \frac{-n_0}{d_0} = -1.08\qquad x_1 = \frac{n_0}{d_0} = 1.08\qquad x_{20} = n_1 - \frac{n_0 d_1}{d_0} = -0.847\tikzmark{end}$
Hence:
\begin{align*}
\frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1.08}{s} - \frac{1.08s + 0.847}{s^2 + 0.8-2s + 6.489} \\
\shortintertext{Completing the square:}
\frac{G_{\delta_r}^{\beta}(s)}{s} &= \frac{1.08}{s} - \frac{1.08s + 0.847}{(s + 0.401)^2 + 6.328} \\
\shortintertext{Inverse Laplace:}
\mathcal{L}^{-1}\left\{ \frac{G_{\delta_r}^{\beta}(s)}{s} \right\} &=  1.08 - e^{-.401t} \left(1.08 \cos(t\sqrt{6.328}) + \frac{0.847}{\sqrt{6.328}} \sin(t\sqrt{6.328}) \right)
\end{align*}

\begin{tikzpicture}[remember picture,overlay]
\draw[line width=1.5pt,blue]
([xshift=-1ex,yshift=2.5ex]current page text area.west|-{pic cs:start})
rectangle
([yshift=-2.5ex]current page text area.east|-{pic cs:end});
\end{tikzpicture}

\end{document}


• The original alignment is lost. – karlkoeller Apr 13 '14 at 16:43
• @karlkoeller although I didn't like much the original alignment, I've updated my answer providing a much simpler option (not requiring TikZ) and keeping the original alignment, but simplifying the code. – Gonzalo Medina Apr 13 '14 at 20:19
• Thanks @Gonzalo, that helps a lot. I also appreciate your simplifications to the code, i was getting a bit carried away :) – n.dubau Apr 14 '14 at 1:16
• The original alignment is not the same, anyway. But the answer is good, so +1. – karlkoeller Apr 14 '14 at 4:53