Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 '13 at 19:39
    
have a look at mdframed –  cmhughes Mar 19 '13 at 21:05

2 Answers 2

up vote 8 down vote accepted

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}
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.