Math & ScienceEquations in a box with a title...

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
EFaden
Posts: 24
Joined: Thu Jun 04, 2009 2:58 am

Equations in a box with a title...

Post by EFaden »

I am looking for a good way to put a group of equations (such as a gather, align, etc) with a title on the top of the box somehow. I have looked at the fancybox and empheq, but have had some trouble getting either to work. The empheq documentation has the "\Garybox" example, but it doesn't seem to want to work for me. And the fancybox documentation has a "\titleframe" example, but that didn't seem to work if I put a \begin{align} or whatever inside of it. Does anyone have any examples of this? Basically I am looking for a way to have a set of equations inside of a box with a label on it. Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Equations in a box with a title...

Post by gmedina »

Hi,

one possibility is to define a new environment using some of the features provided by the framed package; take a look at the following simple example:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\usepackage{framed}

\newenvironment{myequ}[1]
  {\begin{framed}{\noindent\bfseries#1}%
    \addtolength\textwidth{20pt}\par\noindent\hspace*{-10pt}\rule{\textwidth}{.4pt}}
  {\end{framed}}
\begin{document}

\begin{myequ}{Some equation}
\begin{align}
  a &= b\\
    &= c
\end{align}
\end{myequ}

\end{document}
Of course, feel free to adapt my example according to your needs.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Equations in a box with a title...

Post by localghost »

I just copied the necessary code from the empheq manual and have no problems.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{empheq}
\usepackage{xcolor}

\definecolor{shadecolor}{cmyk}{0,0,0.41,0}
\definecolor{light-blue}{cmyk}{0.25,0,0,0}
\newsavebox{\mysaveboxM} % M for math
\newsavebox{\mysaveboxT} % T for text

\newcommand*\Garybox[2][Example]{%
  \sbox{\mysaveboxM}{#2}%
  \sbox{\mysaveboxT}{\fcolorbox{black}{light-blue}{#1}}%
  \sbox{\mysaveboxM}{%
    \parbox[b][\ht\mysaveboxM+.5\ht\mysaveboxT+.5\dp\mysaveboxT][b]{\wd\mysaveboxM}{#2}%
  }%
  \sbox{\mysaveboxM}{%
    \fcolorbox{black}{shadecolor}{%
      \makebox[\linewidth-10em]{\usebox{\mysaveboxM}}%
    }%
  }%
  \usebox{\mysaveboxM}%
  \makebox[0pt][r]{%
    \makebox[\wd\mysaveboxM][c]{%
      \raisebox{\ht\mysaveboxM-0.5\ht\mysaveboxT+0.5\dp\mysaveboxT-0.5\fboxrule}{\usebox{\mysaveboxT}}%
    }%
  }%
}

\begin{document}
  \begin{empheq}[box=\Garybox]{align}
    \sum \mathbf{F} &= \mathbf{0} \\
    \sum F_{x} \,\mathbf{i} + \sum F_{y} \,\mathbf{j} + \sum F_{z} \,\mathbf{k} &= \mathbf{0} \\
    \sum F_{x} &= 0 \\
    \sum F_{y} &= 0 \\
    \sum F_{z} &= 0
  \end{empheq}
\end{document}

Best regards
Thorsten
EFaden
Posts: 24
Joined: Thu Jun 04, 2009 2:58 am

Re: Equations in a box with a title...

Post by EFaden »

Weird. It didn't work when I copied it, but when I copied yours it did. Is there a way to modify it easily to have the box include the equation numbers?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Equations in a box with a title...

Post by localghost »

Not an easy way. Expanding the box to the full text width would shift the equation numbers down. At the moment I have no workaround.
Post Reply