# toprule and bottomrule for figures

I have some figure that includes an external file and I would like to include a horizontal line around the included file such that the result is:

------------
figure
------------
caption


I have tried

\begin{figure}
\centering
\hrulefill\\
\includegraphics{foo.pdf}
\hrulefill\\
\caption{A figure.}
\end{figure}


but the second \hrulefill won't print.

With use of \rule:

\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage[skip=1ex]{caption}

\begin{document}
\begin{figure}[ht]
\centering
\rule[0.5ex]{\linewidth}{1pt} % <---
\includegraphics{example-image-duck}
\rule[2ex]{\linewidth}{1pt}   % <---
\caption{A figure.}
\end{figure}
\end{document}


• Excellent, thanks! What does [2ex] do? Jun 22, 2020 at 11:26
• @bumblebee, [2ex] lift rule for heights of two letters x. Jun 22, 2020 at 11:33

You may define a ruled environment that internally uses tabular* and the rules of booktabs.

\documentclass{article}
\usepackage{booktabs}
\usepackage{graphicx}

\newenvironment{ruled}{%
\par
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ccc@{}}
}{%
&\\\bottomrule
\end{tabular*}\par
}

\begin{document}

\begin{figure}[htp]

\begin{ruled}
\includegraphics[width=0.3\textwidth]{example-image}
\end{ruled}

\caption{A figure}\label{label}

\end{figure}

\begin{figure}[htp]

\begin{ruled}
\includegraphics[width=0.3\textwidth]{example-image-b}
\end{ruled}

\caption{Two figures}\label{label2}

\end{figure}

\end{document}


This way if you change your mind, you can simply modify the definition of ruled. For instance,

\newcommand{ruled}{\par\centering}{\par}


would remove the rules in all places.