2

I need to generate figures with a caption above and an explanative text below. The figure below shows the desired output.

The type of caption alignment that I need.

I have found some similar working examples, but up to now none worked right for different reasons.

Below you can find the best I could do up to now. It was done essentially "by hand". I used a combination of \captionbox and \parbox which has to be adjusted for each figure and the resulting alignment clearly is not perfect. I have also tried with the package floatrow, but I could not set it properly for this case.

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{lipsum}

\captionsetup{
    singlelinecheck=false,
    figureposition=top
    }

\begin{document}

\lipsum[2]

\begin{figure}[hbt]
    \centering
    \captionbox{
        \lipsum[1][1] \label{fig1} \vskip-4ex
        }       
        {
        \fbox{\includegraphics[width=0.80 \textwidth]{SomeFigureHere}}
        } \\
    \parbox{0.80\textwidth}{\small Source: \lipsum[1][1]}
\end{figure}

\end{document}

A simple unsatisfactory realization

Added information after the answer from @Bernard.

@Bernard's answer can be used to answer my question. Nonetheless, if there is some other answer more economic, it is welcome as well. With the provided answer, \captionsetup would need to be called each time a new figure is inserted. This since each figure can have a different width.

Bellow I append the complete code for two figures using the given answer:

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{copyrightbox}
\usepackage{lipsum}

\captionsetup{
    singlelinecheck=false,
    figureposition=top,
    skip=1ex
    }

\makeatletter
\renewcommand{\CRB@setcopyrightfont}{%
\small
}
\begin{document}

\lipsum[2]

\captionsetup{width = 0.8\textwidth}
\begin{figure}[hbt]
    \centering
    \caption{
        \lipsum[1][1] \label{fig1}% \vskip-4ex
        }
        \copyrightbox[b]{\includegraphics[width=0.80 \textwidth]{Piero_di_Cosimo_1}}
       {\small Source: \lipsum[1][1]}
\end{figure}

\captionsetup{width = 0.5\textwidth}
\begin{figure}[hbt]
    \centering
    \caption{
        \lipsum[1][1] \label{fig1}% \vskip-4ex
        }
        \copyrightbox[b]{\includegraphics[width=0.50 \textwidth]{Piero_di_Cosimo_1}}
       {\small Source: \lipsum[1][1]}
\end{figure}

\end{document} 

enter image description here

1
  • I do not like this caption style, but I have to follow these specifications...
    – Davi
    Jul 12, 2021 at 1:35

1 Answer 1

4

I propose this solution with the copyrightbox package:

\documentclass{article}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{copyrightbox}
\usepackage{lipsum}

\captionsetup{
    singlelinecheck=false,
    figureposition=top,
    width = 0.8\textwidth,
    skip=1ex
    }

\makeatletter
\renewcommand{\CRB@setcopyrightfont}{%
\small
}
\begin{document}

\lipsum[2]

\begin{figure}[hbt]
    \centering
    \caption{
        \lipsum[1][1] \label{fig1}% \vskip-4ex
        }
        \copyrightbox[b]{\includegraphics[width=0.80 \textwidth]{Piero_di_Cosimo_1}}
       {Piero di Cosimo: \emph{The Death of Procris} (ca 1495). Oil on poplar. National Gallery (London)}
\end{figure}

\end{document} 

enter image description here

Edit: Another code using the\ffigbox command from floatrow, in addition to \copyrightbox, to have an automatic adjustment of the caption on the figure width:

\floatsetup[figure]{capposition=top}
    \begin{figure}[hbt]
        \centering
       \ffigbox[\FBwidth]{\caption{
            \lipsum[1][2] \label{fig2}% 
            }}
            {\copyrightbox[b]{\includegraphics{Gauguin}}
           {Paul Gauguin: \emph{Where Do We Come From? What Are We? Where Are We Going?} (1897-1898). Museum of Fine Arts (Boston)}}

enter image description here \end{figure}

6
  • Interesting approach (and with a nice painting). The alignment is better than in my original code. However, it does not truly answers the question since the captions were set to have the global width value of 0.8\textwidth. This means that if I insert a second figure with width=0.5\textwidth the caption would not have the same extension of the figure. Is it possible for the caption width to always follow the figure width?
    – Davi
    Jul 11, 2021 at 23:29
  • @Davi -- I don't know this package, but if you look closely at the code, the width is actually applied to the \includegraphics, so all three pieces are set to the same width at once. Very nice idea. Jul 12, 2021 at 0:46
  • @barbarabeeton , I don't know if I understand your comment. The width in the answer is set both in the \includegraphics and the \captionsetup. The includesgraphics width is a local one, but the \captionsetup is in principle global. However, I just realised that it is possible to call \captionsetup together with each time \begin{figure} is invoked. So, although there may be a more economical way, this is already an answer to my question.
    – Davi
    Jul 12, 2021 at 1:16
  • 2
    @Davi -- Oops! I did look closely to see if there were separate settings, but obviously, I missed that. Still, the two settings are easily coordinated, so it's not complicated, and worth a plus. Jul 12, 2021 at 1:40
  • 1
    @Davi: I've added a variant code using also floatrow to automatically have the caption width equal to the figure width.
    – Bernard
    Jul 12, 2021 at 9:04

You must log in to answer this question.

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