5

I'm trying to make a box around my figure like the ones in Benjamin Pierce "Types and Programming Languages" book and Luca Cardelli paper "Types Systems". Such boxes have horizontal rules and only small vertical lines on the corners.

I can't really get the hack, does anyone have any idea on how to do this?

2
  • It is easy with tikz, but I would say that it is overkill. Better wait to pure-latex solutions. Unless you already are using tikz in your document, of course.
    – JLDiaz
    Mar 19, 2013 at 19:39
  • have a look at mdframed
    – cmhughes
    Mar 19, 2013 at 21:05

2 Answers 2

8

enter image description here

\documentclass{article}

\newenvironment{foo}[2][c]
{\begin{minipage}[#1]{#2}\centering
\hrule height2pt
\centerline{\vrule width2pt height 5pt\hfill \vrule width2pt height 5pt}
\begin{minipage}{\dimexpr\textwidth-4pt-1em}}
{\end{minipage}
\centerline{\vrule width2pt height 5pt\hfill \vrule width2pt height 5pt}
\hrule height2pt
\end{minipage}}

\begin{document}


\begin{foo}[b]{.3\textwidth}

A \dotfill\ B \dotfill\ C\\
A \dotfill\ B \dotfill\ C\\
A \dotfill\ B \dotfill\ C
\end{foo}
\hfill
\begin{foo}[t]{.3\textwidth}

A \dotfill\ B \dotfill\ C\\
A \dotfill\ B \dotfill\ C\\
A \dotfill\ B \dotfill\ C
\end{foo}


\end{document}
3

Here's another possibility using the float and caption packages to add the rules to the standard figure environment:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{float}
\usepackage{caption}

\DeclareCaptionFormat{myrule}{%
  \rule{1pt}{8pt}%
  \kern-1pt\raisebox{-1pt}{\rule{\linewidth}{1pt}}%
  \kern-1pt\rule{1pt}{8pt}\par\smallskip#1#2#3}

\makeatletter
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled%
\def\@fs@pre{\rule{1pt}{8pt}\kern-1pt\raisebox{8pt}{\rule{\linewidth}{1pt}}\kern-1pt\rule{1pt}{8pt}}%
\def\@fs@post{}%
\def\@fs@mid{}%
\let\@fs@iftopcapt\iffalse%
}
\makeatother

\floatstyle{ruled}
\restylefloat{figure}
\captionsetup[figure]{format=myrule,labelsep=colon}

\begin{document}

\begin{figure}
\centering
\includegraphics{image}
\caption{A test ruled figure}
\end{figure}

\end{document}

enter image description here

The float package was used to build the upper set of rules, and the caption package was used to define the lower ones.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .