TransWikia.com

Remove space after captionof

TeX - LaTeX Asked on April 17, 2021

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=.25linewidth]{example-image}
tcblower
captionof{example}{Caption content, notice the big space that I'm trying to remove}
end{texample}

lipsum[2]

end{document}

2 Answers

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=.25linewidth]{example-image}
tcblower
captionsetup{skip=0pt}
captionof{example}{Caption content}
end{texample}

lipsum[2]

end{document}

Correct answer by Vincent on April 17, 2021

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=.25linewidth]{example-image}
end{texfigure}

lipsum[2]

end{document}

enter image description here

Answered by Ignasi on April 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP