[Tex/LaTex] How to make \captionof have: 1) more space between image and caption & 2) encompass less width than \textwidth

captionsgraphics

This question is specifically regarding \captionofs, which I have been using instead of captionss since the latter are floating.

(Unfortunately, I have experienced that \captionof's sometimes interfere with something simple as an abstract, which I thus had to remove.)

Regarding the lay-out of \captionofs:

  1. I would like to have the \captionof encompass less width than the \textwidth.

    Already, I obtained this using:

    \parbox{0.9\linewidth}{\captionof{figure}{
    

    But, I inserted the desire into the question anyway, because there might be a more elegant way to solve both questions.

  2. Now, I would like to increase space between the vertical space between the caption and the image (but specifically for \captionofs, instead of normal \captions -> I have not been able to achieve this considering other similar questions for \captions).

Best Answer

The vertical distance between \caption and the image (or whatever) can be controlled with \captionsetup{skip=...} where ... stands for some appropiate value. The standard value for article, report and book is 10pt.

Please note that the caption manual clearly states that still the class or another package might take control of the skip between figure or table content (the figure/table etc. environments are defined by the class, not by caption. skip= actually sets \abovecaptionskip, a LaTeX length register. Changing \belowcaptionskip could help too.

For the margins, the minmargin=... and maxmargin=... option keys can be used, see the example and the screen shot.

\documentclass{article}


\usepackage{graphicx}
\usepackage{caption}
\usepackage{blindtext}
\usepackage{showframe}

\newcommand{\fakeverb}[1]{\texttt{\textbackslash #1}}
\begin{document}


\captionsetup{skip=5pt}
\begin{figure}
  \centering
  \fbox{\includegraphics[scale=0.5]{ente.jpg}}
  \hrule
  \setlength{\belowcaptionskip}{10pt}
  \caption{Caption with \fakeverb{caption} for this very nice image of a cute duck}
\end{figure}

{
  \centering

  \fbox{\includegraphics[scale=0.5]{ente.jpg}}
  \hrule
  \captionof{figure}{Caption with \fakeverb{captionof} for this very nice image of a cute duck}
}

\clearpage

\captionsetup{skip=2pt, minmargin=3cm, maxmargin=3cm}
{
  \centering

  \fbox{\includegraphics[scale=0.5]{ente.jpg}}
  \hrule
  \captionof{figure}[Too long for LoF]{\fakeverb{captionof} with a long text: \blindtext}
}


\end{document}

enter image description here