5

Right now, I have

\begin{gather}
Eq1
\\ Eq2
\\ Eq3
\end{gather}

where variables ... are defined as

\begin{gather}
Eq4
\\ Eq5
\end{gather}

I would like to put a box around all of this including the text "where variables ... are defined as". Is it possible to do this using the empheq environment?

Gonzalo Medina
  • 505,128
KevinB
  • 291

1 Answers1

5

Yes, it's possible, and you have several options depending on the desired result. Below I show six different possibilities.

enter image description here

The code:

\documentclass{article}
\usepackage[vmargin=1cm]{geometry}
\usepackage{amsmath}
\usepackage[many]{tcolorbox}
\usepackage{empheq}

\begin{document}

\begin{empheq}[box=\fbox]{gather}
Eq1
\\ Eq2
\\ Eq3
\\ \notag\text{where variables ... are defined as}
\\ Eq4
\\ Eq5
\end{empheq}

\begin{empheq}[box=\fbox]{gather}
Eq1
\\ Eq2
\\ Eq3
\\ \notag\text{\parbox{.7\linewidth}{where variables ... are defined as}}
\\ Eq4
\\ Eq5
\end{empheq}

\begin{empheq}[box=\tcbhighmath]{gather}
Eq1
\\ Eq2
\\ Eq3
\\ \notag\text{where variables ... are defined as}
\\ Eq4
\\ Eq5
\end{empheq}

\begin{empheq}[box=\tcbhighmath]{gather}
Eq1
\\ Eq2
\\ Eq3
\\ \notag\text{\parbox{.7\linewidth}{where variables ... are defined as}}
\\ Eq4
\\ Eq5
\end{empheq}

\begin{tcolorbox}[enhanced,oversize,breakable,colframe=cyan,colback=cyan!20,top=-\abovedisplayskip,bottom=0pt]
\begin{gather}
Eq1
\\ Eq2
\\ Eq3
\end{gather}
where variables ... are defined as
\begin{gather}
Eq4
\\ Eq5
\end{gather}
\end{tcolorbox}

\noindent\makebox[\linewidth]{\fcolorbox{orange}{orange!10}{%
\begin{minipage}[t]{\linewidth}
\vskip-\abovedisplayskip
\begin{gather}
Eq1
\\ Eq2
\\ Eq3
\end{gather}
where variables ... are defined as
\begin{gather}
Eq4
\\ Eq5
\end{gather}
\end{minipage}}}

\end{document}

Explanation

  • In options one through four, instead of two gather environments I used just one. The text was written using \text.

  • In options two and four, the text was additionally placed inside a \parbox, so you can control its width and have possible line breaks.

  • Options one and two use a standard empheq environment with \fbox as the framing method.

  • Options three and four use the interaction between tcolorbox and empheq; the framing method is \tcbhighmath.

  • In option five, a tcolorbox was used to surround both gather environments and the text; page breaks are allowed.

  • In option six, a \fcolorbox was used to surround both gather environments and the text; page breaks are not allowed since a minipage was used.

Gonzalo Medina
  • 505,128
  • Thanks for your quick and helpful response. With tcolorbox, is there a way to change the width of the frame? – KevinB Jul 25 '15 at 17:43
  • @KevinB You're welcome. I edited my answer (in case you didn't noticed it). Regarding your question, you can use boxrule as in \begin{tcolorbox}[oversize,breakable,colframe=cyan,colback=cyan!20,boxrule=0.4pt] ...\end{tcolorbox} (change 0.4pt to the desired value.) – Gonzalo Medina Jul 25 '15 at 17:47
  • I did see your edit. Thanks for such a thorough answer with the different options. I like the tcolorbox option the best. However when I use boxrule:
    \begin{tcolorbox}[oversize,breakable,colframe=black,colback=white!20,boxrule=0.4 p‌​t]
    
    
    

    I'm getting an error

    " Illegal unit of measure (pt inserted).

    p l.351 ...ck,colback=white!20,boxrule=0.4 p‌​t] Dimensions can be in units of em, ex, in, pt, pc, cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!"
    – KevinB Jul 25 '15 at 17:53
  • @KevinB for some reason there's a strange character in your code in the pt part (probably a result of copy-paste). Delete 0.4 pt and write it again directly from your keyboard. – Gonzalo Medina Jul 25 '15 at 18:04
  • Thanks, that works. Unfortunately with tcolorbox, the equations I want to box are getting split into two boxes because they extend beyond the bottom of the page. Therefore, I think I will use fcolorbox because as you mentioned, that doesn't allow page breaks. With fcolorbox, how should I specify the frame width? Thanks for all your help. – KevinB Jul 25 '15 at 18:28
  • @KevinB delete breakable from the tcolorbox options and no page breaks will occur. – Gonzalo Medina Jul 25 '15 at 18:31
  • it would be nice to get rid of the extra blank line at the top of examples 5 and 6. – barbara beeton Jul 26 '15 at 12:31
  • @barbarabeeton You're right. I tried to better balnce the spaces above and below for cases five and six. I think it looke better now. Thanks. – Gonzalo Medina Jul 26 '15 at 17:48
  • @Gonzalo In the case where the "breakable" argument is used, is there any way to have it look like one box (and not be two separate boxes) if it extends beyond one page? In other words, I mean I would like to have the bottom line of the box not be drawn on page 1 and the top line of the box not be drawn on page 2, so that it looks like one continuous box encompassing two pages rather than two separate boxes. – KevinB Jul 26 '15 at 18:53
  • @KevinB Sure. Add enhanced to the options: \begin{tcolorbox}[enhanced,oversize,breakable...]. I've added this as an edit. – Gonzalo Medina Jul 26 '15 at 19:03
  • @Gonzalo: After adding "enhanced" to the options, there is a very thin bottom line on page 1 and a very thin top line on page 2. This is better than the normal thick line before, but I would prefer not to have any line on the bottom of page 1 and top of page 2. Is there a way to do this? – KevinB Jul 26 '15 at 23:55
  • @KevinB To get rid of the very thin line: replace enhanced by enhanced jigsaw. – Thomas F. Sturm Jul 27 '15 at 05:35