5

I'm trying to embed a picture and its caption inside a tcolorbox with a special layout. Indeed, the caption has to be placed in the "frame" made around the picture.

I've found decent examples here, and I managed to get 90% of what I'm trying to have. I've made a bicolor tcolorbox with the image in the upper part and the caption in the lower part, using the \captionof macro.

However, an extra space is placed after the caption. If I replace the caption by some static text I don't have this problem.

I've search the documentation of the package, and the option \captionsetup{belowskip=0pt} doesn't have any effect.

How can I reduce the space produced by the captionof macro ?

MWE output

Here is the MWE :

\usepackage[svgnames,usenames,dvipsnames,table]{xcolor}
\usepackage[showframe=false]{geometry}
\usepackage[many]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{caption}

\usepackage{lipsum}

\newtcolorbox{texample}[1][]{float, notitle, #1}

\usepackage{float}
\floatstyle{plain}
\newfloat{example}{thp}{lop}
\floatname{example}{\textsc{Figure}}


\begin{document}
\lipsum[2]

\begin{texample}[bicolor,sharp corners,
    colback=white,colframe=gray!20,colbacklower=gray!20,
    top=1mm,bottom=1mm,middle=1mm]
\centering
\includegraphics[width=.25\linewidth]{example-image}
\tcblower
\captionof{example}{Caption content, notice the big space that I'm trying to remove}
\end{texample}

\lipsum[2]

\end{document}
6

It is sometimes confusing to distinguish between aboveskip and belowskip because their meaning sometimes change according to the value of position. It is discussed in section 2.6 of caption's documentation. To avoid confusion in a case like this, it might be better to set skip to zero.

\documentclass{article}
\usepackage[svgnames,usenames,dvipsnames,table]{xcolor}
\usepackage[showframe=false]{geometry}
\usepackage[many]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{caption}

\usepackage{lipsum}

\newtcolorbox{texample}[1][]{float, notitle, #1}

\usepackage{float}
\floatstyle{plain}
\newfloat{example}{thp}{lop}
\floatname{example}{\textsc{Figure}}


\begin{document}
\lipsum[2]

\begin{texample}[bicolor,sharp corners,
    colback=white,colframe=gray!20,colbacklower=gray!20,
    top=1mm,bottom=1mm,middle=1mm]
\centering
\includegraphics[width=.25\linewidth]{example-image}
\tcblower
\captionsetup{skip=0pt}
\captionof{example}{Caption content}
\end{texample}

\lipsum[2]

\end{document}
1
  • Exactly what I needed, thanks. – 3isenHeim Feb 3 at 7:29
2

This is not an answer to this particular question but an alternative construction for what I understand OP wants.

OP wants to embed a image into a tcolorbox whith a caption as title but with this title below the image instead of usual upper position in tcolorboxes.

tcolorbox package has some commands to declare floating boxes and include them into the list of figures or whatever float. In this case the title starts with Figure ... like any regular caption. Furthermore, flip title option allows to place the title box below the box content. This way it's not necesary to use a bicolor box and captionof package to construct the captions.

Here you have an example:

\documentclass{article}
\usepackage[svgnames,usenames,dvipsnames,table]{xcolor}
\usepackage[showframe=false]{geometry}
\usepackage[many]{tcolorbox}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{lipsum}

\newtcolorbox[blend into=figures]{texfigure}[2][]{%
    float, sharp corners, colback=white, colframe=gray!20, 
    enhanced, coltitle=black, halign title=center, flip title={sharp corners, colback=gray!20}, before upper={\centering}, title={#2}, #1}

\begin{document}
\lipsum[2]

\begin{texfigure}{This is the caption}
\includegraphics[width=.25\linewidth]{example-image}
\end{texfigure}

\lipsum[2]

\end{document}

enter image description here

1
  • For integration constraints, in my code the caption always comes after the picture itself, and thus I can't make your example compatible :/ – 3isenHeim Feb 18 at 13:59

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.