4

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.

2 Answers 2

2

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}

enter image description here

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

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@{}}
  \toprule\addlinespace&
}{%
  &\\\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-a}\quad
\includegraphics[width=0.3\textwidth]{example-image-b}
\end{ruled}

\caption{Two figures}\label{label2}

\end{figure}

\end{document}

enter image description here

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.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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