24

I'd like to place a border / frame around my figure.

The figure is a bunch of equations:

\begin{figure}[ht]
    \[ eqn 1 \]

    \[ eqn 2 \]

    \[ eqn 3 \]

    \caption{\label{myfig} My caption.}
\end{figure}

I've tried putting an \fbox{...} and \framebox[\textwidth]{...} around the equations but it doesn't work.

Preferably, I'd like the border to not include the caption.

Any hints are welcome...


Related question (though it concerns \includegraphics instead):

2
  • it seems there's no [figure] tag. any reason why? if not, could someone with 300+ perhaps "invent it" by adding it to this question?
    – aioobe
    Aug 22, 2011 at 11:13
  • 2
    There's a floats tag which is for questions about figure and table environments, which are very similar. I added it to your question. figures is an alias tag which maps to floats.
    – Stefan Kottwitz
    Aug 22, 2011 at 13:24

4 Answers 4

17

With the package mdframed or framed this is possible

\documentclass{article}
\usepackage{mdframed}
\begin{document}
\begin{figure}[ht]
\begin{mdframed}
    \[ eqn 1 \]

    \[ eqn 2 \]

    \[ eqn 3 \]
\end{mdframed}
    \caption{\label{myfig} My caption.}
\end{figure}
\end{document}
4
  • 3
    Thanks, what's the difference between framed and mdframed?
    – aioobe
    Aug 22, 2011 at 11:20
  • @aioobe mdframed has more options and has, in my opinion, a more user friendly interface for customising it. (mdframed frames can also break nicely across pages, but since you're using it in a float, this doesn't matter)
    – Seamus
    Aug 22, 2011 at 11:21
  • 2
    Hmmmm... When I try this (now, 2.5 years after you answered), I get a partial frame (around only the right and bottom) and not a complete frame. Apr 13, 2014 at 19:54
  • Same here, @Shay Dec 11, 2016 at 17:31
7

Using memoir (a package for books), you can use the

\begin{framed}
[...]
\end{framed} 

construct. See manual pages 181-183.

6

IF you don't want to use the memoir documentclass, as is suggested in @Sardathrion's answer, you could use the float package and, in particular, its \floatstyle{boxed} and \restylefloat commands.

A nice feature of the float package is that it provides the H location specifier, as in "I really want this float HERE and nowhere else". Two idiosyncracies of the "boxed" float style are (i) the width of the boxes is that of \textwidth (plus a small fudge factor, so that an object of full \textwidth width fill fit) and (ii) captions of table and figure floats will always be placed below the respective objects. (To change this behavior, one will have to delve into the innards of the code of the float package.)

Aside: if you set tables with the "boxed" float style, you'll definitely want to use as few \hline commands as possible (or, even better, none at all).

\documentclass{article}
\usepackage{float,lipsum}
\floatstyle{boxed}
\restylefloat{table}
\restylefloat{figure}
\begin{document}
\lipsum[1]
\begin{figure}[H]
\centering
ABCDEFG
\caption{A very simple figure}
\end{figure}

\bigskip
\begin{table}[h]
\caption{An equally simple table}
\begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}rlrlr@{}}
Here & There & Here & There & Here & There 
\end{tabular*}
\end{table}

\lipsum[2]
\end{document}

enter image description here

2

tcolorbox is another alternative for boxing any kind of contents, even equations.

Following code shows two example, both produce floating objects, the first shows the box around the equation but with an independent caption and the second includes the caption as a title for the box.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}

\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htb,
title={#2},#1}

\begin{document}
\begin{figure}
\begin{tcolorbox}
\[ \sin^2x+\cos^2x=1\]

\[ 1 + \frac{1}{\tan^2x}=\frac{1}{\sin^2x}\]
\end{tcolorbox}
\caption{Some title for these equations}
\end{figure}

\begin{myfigure}{Some title for these equations}
\[ \sin^2x+\cos^2x=1\]

\[ 1 + \frac{1}{\tan^2x}=\frac{1}{\sin^2x}\]
\end{myfigure}

\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 .