# Placing text and equations inside a box

I have a paragraph that contains text, inline equations and centred equations, and I'd like to put the whole thing in a box that's centred horizontally in the page. It's a key paragraph, so I wanted to box it so that it stands out. I just want a simple box: black outline, white fill, no curved corners.

I had a look at questions with similar titles, but couldn't find anything that both worked and suited my needs. If it helps, see below for the particular paragraph I want to put in a box:

\documentclass[12pt article]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

Let $a(b) = \left\{ \begin{array}{c l} hi & \mbox{if } t^5 \mbox{ reduced} \\ t & \mbox{otherwise} \end{array} \right.$, $xyz = \left\{ \begin{array}{c l} GH & \mbox{if } tr^{\pi} \mbox{ secluded} \\ x& \mbox{otherwise} \end{array} \right.$, $s = \left\{ \begin{array}{c l} up^{-5} & \mbox{if } t^55 \mbox{ reduced} \\ lo & \mbox{otherwise} \end{array} \right.$. \\ \\

Define the magician $M_n$ recursively, where $M_1 = \bigstar$ and

\begin{center} $\begin{array}{r} M_{3} = tr(Md) \\ M_{hat} = norbert(2304) \\ Mtri = solution \end{array}$ \end{center}

where $z$ is the smallest integer such that $z \notin \{ 0 \}$. Terminate the magician at $M_{3}$ where $3$ is such that $M_{3}, ... , M_{3}$ have all already appeared in $M_1, ... , M_{t},$ i.e.

\begin{center}

$Mtr = g, \underbrace{hi, hello, good day}_{\mbox{cousins}}, \underbrace{1,2,3,4,4,5}_{\mbox{enemies of first cousin of } g} , ... \ , M_{3}, M_{3}, M_{3}$

\end{center}

where $i$ is smallest such that $rt \neq z$.

\end{document}


Thanks! I wasn't sure what tags to use - I'd welcome any changes.

-
In case anyone was wondering from the content - yes, this is part of a breakthrough paper in mathematics that will change the way we view everything –  Matt Jan 11 '12 at 16:45
It already did. –  percusse Jan 11 '12 at 16:48

if you do not need a pagebreak inside the box, simply use a tabular, otherwise look at the package framed

\documentclass[12pt article]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}

\begin{center}
\begin{tabular}{|p{0.9\linewidth}|}\hline % or any other width
\rule{0pt}{5ex}% for more vertical space
Let $a(b) = \left\{ \begin{array}{c l} hi & \mbox{if } t^5 \mbox{ reduced} \\ t & \mbox{otherwise} \end{array} \right.$, $xyz = \left\{ \begin{array}{c l} GH & \mbox{if } tr^{\pi} \mbox{ secluded} \\ x& \mbox{otherwise} \end{array} \right.$, $s = \left\{ \begin{array}{c l} up^{-5} & \mbox{if } t^55 \mbox{ reduced} \\ lo & \mbox{otherwise} \end{array} \right.$. \\ \\

Define the magician $M_n$ recursively, where $M_1 = \bigstar$ and

\begin{center} $\begin{array}{r} M_{3} = tr(Md) \\ M_{hat} = norbert(2304) \\ Mtri = solution \end{array}$ \end{center}

where $z$ is the smallest integer such that $z \notin \{ 0 \}$. Terminate the magician at $M_{3}$ where $3$ is such that $M_{3}, ... , M_{3}$ have all already appeared in $M_1, ... , M_{t},$ i.e.

\begin{center}
$Mtr = g, \underbrace{hi, hello, good day}_{\mbox{cousins}}, \underbrace{1,2,3,4,4,5}_{\mbox{enemies of first cousin of } g} , ... \ , M_{3}, M_{3}, M_{3}$
\end{center}

where $i$ is smallest such that $rt \neq z$.\\\hline
\end{tabular}
\end{center}

\end{document}


-
Thanks, this was helpful. Is there any way to increase the (/create a) gap between the top line and the first line of text? –  Matt Jan 11 '12 at 17:48
Put before "Let" at the beginning of the first line \rule{0pt}{5ex}. Could also be done with the tabular column specification, but then it may be a problem when another box has no array in the first line. –  Herbert Jan 11 '12 at 17:53
see my edited code –  Herbert Jan 11 '12 at 18:00

You could also use the mdframed package to define a custom environment. This has the advantages that you get all the flexibility inherent with tikz (if you use the framemethod=tikz option) and will also work across page boundaries.

## Note:

• I have taken the liberty to reformat the equations (but feel free to adjust as you desire).

## Code:

\documentclass[12pt article]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{calc}
\usepackage[framemethod=tikz,xcolor=true]{mdframed}
\newmdenv[%
leftmargin=0.5cm,
backgroundcolor=yellow!10,%
roundcorner=5pt,%
tikzsetting={draw=red, line width=2.0pt}%
]{SpecialText}%

\newcommand*{\Format}[1]{\makebox[\widthof{$xyz$}][r]{$#1$}}%
\newcommand*{\PhantomLet}{\mbox{\hphantom{Let }}}%

\begin{document}
\begin{SpecialText}
Let $\Format{a(b)} = \left\{ \begin{array}{c l} hi & \mbox{if } t^5 \mbox{ reduced} \\ t & \mbox{otherwise} \end{array} \right.$,

\smallskip
\PhantomLet $\Format{xyz} = \left\{ \begin{array}{c l} GH & \mbox{if } tr^{\pi} \mbox{ secluded} \\ x& \mbox{otherwise} \end{array} \right.$,

\smallskip
\PhantomLet $\Format{s} = \left\{ \begin{array}{c l} up^{-5} & \mbox{if } t^55 \mbox{ reduced} \\ lo & \mbox{otherwise} \end{array} \right.$. \\ \\

Define the magician $M_n$ recursively, where $M_1 = \bigstar$ and
%
\begin{align*}
M_{3}   &=   tr(Md) \\
M_{hat} &=   norbert(2304) \\
Mtri    &=   solution
\end{align*}
%
where $z$ is the smallest integer such that $z \notin \{ 0 \}$. Terminate the magician at $M_{3}$ where $3$ is such that $M_{3}, ... , M_{3}$ have all already appeared in $M_1, ... , M_{t},$ i.e.
%
$Mtr = g, \underbrace{hi, hello, good day}_{\mbox{cousins}}, \underbrace{1,2,3,4,4,5}_{\mbox{enemies of first cousin of } g} , ... \ , M_{3}, M_{3}, M_{3}$
%
where $i$ is smallest such that $rt \neq z$.
\end{SpecialText}
\end{document}

-

You can try this:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{center}
\fbox{%
\begin{minipage}{.9\textwidth}
Let
\begin{align*}
a(b) &=
\left\{ \begin{array}{@{}c l}
hi & \text{if $t^5$ reduced} \\
t  & \text{otherwise}
\end{array} \right.
&
xyz &=
\left\{ \begin{array}{@{}c l}
GH & \text{if $tr^{\pi}$ secluded} \\
x  & \text{otherwise}
\end{array} \right.
\\
s &=
\left\{ \begin{array}{@{}c l}
up^{-5} & \text{if $t^{55}$ reduced} \\
lo      & \text{otherwise}
\end{array} \right.
\end{align*}

Define the magician $M_n$ recursively, where $M_1 = \bigstar$ and
\begin{align*}
M_{3}   &= \textit{tr}(Md) \\
M_{hat} &= \textit{norbert}(2304) \\
Mtri    &= \textit{solution}
\end{align*}
where $z$ is the smallest integer such that $z \notin \{ 0 \}$. Terminate the magician at
$M_{3}$ where $3$ is such that $M_{3},\dots, M_{3}$ have all already appeared in $M_1, \dots, M_{t}$, i.e.,
$Mtr = g, \underbrace{\text{hi, hello, good day}}_{\text{cousins}}, \underbrace{1,2,3,4,4,5}_{\text{enemies of first cousin of g}}, \dots , M_{3}, M_{3}, M_{3}$
where $i$ is smallest such that $rt \neq z$.
\end{minipage}}% end of \fbox
\end{center}
\end{document}


Please, look carefully at the code, as yours shows many LaTeX weaknesses, particularly in the use of \mbox and of "multiletter identifiers".

The trick is to \fbox a minipage. There are other methods.

-
Thanks. This is first time I've used LaTeX, still learning as a I go –  Matt Jan 11 '12 at 17:49
@Matt: If you want the text contained with the minipage to "line up" with the margins of the surrounding text, use \noindent\makebox[\textwidth]{\fbox{% \begin{minipage}{\textwidth}...\end{minipage}}} in egreg's answer. \fbox adds some space (2\fboxsep) and rules (2\fboxrule) on the sides of the box, which causes some LaTeX warnings (Overfull \hbox warnings). Therefore, putting the entire thing in a \makebox[\textwidth]{..} without an indent (via \noindent) removes these warnings. Regardless, minipages are not breakable across page boundaries. –  Werner Jan 11 '12 at 18:10