0

I'm looking to get a border/box around the captions for my figures and tables, but without wanting to border the figure/table itself as well. I currently have something that works, but the box takes up the whole text width, and I can't find a way to get it to fit the width of the caption (which is constant, thanks to the caption package).

How can I reduce the width of the frame so that it fits the caption?

MWE:

\documentclass[12pt]{article}
\usepackage[demo]{graphicx}

\usepackage{framed}
\usepackage{caption}
\captionsetup{width=0.45\textwidth}

\begin{document}

\begin{figure}[ht!]
  \centering
  \includegraphics[width=0.5\textwidth]{image.png}
  \begin{framed}
    \caption{
        Here is a reasonably long caption that will be at least two lines, around which I would like a box
    }
    \label{some-image}
  \end{framed}
\end{figure}

\end{document}
1
  • Welcome to TeX.SX! Your example misses a \usepackage[demo]{graphicx}
    – user31729
    Jan 10, 2015 at 13:28

1 Answer 1

2

This uses the tcolorbox package and a lot of its options to generate a framed caption, although this looks a little bit strange, in my point of view.

\documentclass[12pt]{article}
\usepackage[demo]{graphicx}

\usepackage{caption}
\usepackage{tcolorbox}
\captionsetup{width=0.45\textwidth}

\begin{document}

\begin{figure}[ht!]
  \centering
  \includegraphics[width=0.5\textwidth]{image.png}
     \begin{tcolorbox}[left=0mm,right=0mm,width=0.5\textwidth,bottom=0mm,top=0mm,arc=0mm,auto outer arc]
    \caption{%
      Here is a reasonably long caption that will be at least two lines, around which I would like a box
    }%
    \label{some-image}%
    \end{tcolorbox}
\end{figure}

\end{document}

enter image description here

4
  • it does look a bit strange, but I've got certain (odd) rules to work within with this document! how could I decrease the thickness of the border around the caption?
    – Tim
    Jan 10, 2015 at 13:37
  • @Tim: Add boxrule=1mm or any appropiate value to the list of tcolorbox options
    – user31729
    Jan 10, 2015 at 13:40
  • @Tim: You may even use a coloured background ;-)
    – user31729
    Jan 10, 2015 at 13:46
  • 1
    the extra space at the bottom might better be avoided. Jan 10, 2015 at 15:25

This site is temporarily in read-only mode and not accepting new answers.

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