0

I am using a customised caption with subfigures. For example, one of them has two subfigures vertically stacked one on top of the other. What I want to do is to display my caption below figure, starting from the left bottom corner of the figure. But the general solutions such as adjusting caption settings justification=justified does not work and creates enter image description here

My current lines of code creating the image above are

\documentclass[a4paper,11pt]{report}
\usepackage{import}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}

\newcommand\mycaption[2]{\caption{\textbf{#1}\newline\footnotesize#2}}
\captionsetup{font=small, labelfont=bf, singlelinecheck=false, tableposition=bottom, justification=justified}
\begin{document}

\begin{figure}[t]
    \centering
    \subfloat[First figure]
    {
        \label{fig.test1}
        \includegraphics[clip,width=0.6\columnwidth]{figureTest.png} } 
    \vfill 
    \subfloat[Second figure]
    \label{fig.test2}
    {
        \includegraphics[clip,width=0.6\columnwidth]{figureTest.png} } 
    \mycaption{I want to display this caption right below the left corner of the figure.}{Explanation blah blah..}
    \label{fig.test1}
\end{figure}

\end{document}

I see many similar questions, but haven't found the desired solution that works for my customised captions. Would anyone be able to point me to the right direction?

5
  • 1
    Load the threeparttable package and nested your figure environment in a measuredfigure environment.
    – Bernard
    Commented Feb 5, 2021 at 20:07
  • 1
    Basically you need to determine the width used and put the \caption inside a minipage the same width. See tex.stackexchange.com/questions/202046/… Commented Feb 5, 2021 at 23:00
  • @JohnKormylo AFAIK \subfloat of the subfig package does this already internally.
    – user205700
    Commented Feb 6, 2021 at 11:11
  • @Pm - Yes, but not for the figure caption. Commented Feb 6, 2021 at 15:14
  • Thank you for all you comments! @ Bernard, threeparttable worked when I stacked one figure next to the other horizontally but it did not work when I stacked the figure on top of the other as in the example above. I just wonder why it doesn't work vertically... @John, Yes! your suggestion worked in my example. Big thank you.
    – yufiP
    Commented Feb 8, 2021 at 19:24

2 Answers 2

0

I'd use subcaption instead of subfig (which seems to add some small horizontal space).

\documentclass[a4paper,11pt]{report}
\usepackage{graphicx}
\usepackage{subcaption} % also loads caption

\captionsetup{
  font=small,
  labelfont=bf,
  font=bf,
  singlelinecheck=false,
  figureposition=bottom,
  tableposition=bottom,
  justification=justified
}
\captionsetup[subfigure]{font=normalfont}
\newcommand\captionexplain[1]{\par\medskip{\footnotesize#1\par}}

\begin{document}

\begin{figure}[t]
\centering

\begin{subfigure}{0.6\columnwidth}
  \includegraphics[clip,width=\textwidth]{example-image}%
  \caption{First figure\label{fig.test1}}
\end{subfigure}

\medskip

\begin{subfigure}{0.6\columnwidth}
  \includegraphics[clip,width=\textwidth]{example-image}%
  \caption{Second figure\label{fig.test2}}
\end{subfigure}

\begin{minipage}{0.6\columnwidth}
\caption{I want to display this caption right below the left corner 
  of the figure.\label{fig.test}}

\captionexplain{Explanation blah blah..}
\end{minipage}
\end{figure}

\end{document}

I'd not use \mycaption, but a proper auxiliary command, as shown.

enter image description here

1
  • Thank you egreg. Combined with P.M.'s answer below, I will think about whether using \mycaption or a proper auxiliary command is more convenient in my report :)
    – yufiP
    Commented Feb 8, 2021 at 19:38
0

First of all there are extra (unwanted) spaces in front of the image, therefore the caption is not adjusted correctly with the left margin of the image. Removing the extra spaces with % will remove them.

See also: Unwanted spaces

\documentclass[a4paper,11pt]{report}
\usepackage{import}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}

\newcommand\mycaption[2]{\caption{\textbf{#1}\newline\footnotesize#2}}
\captionsetup{font=small, labelfont=bf, singlelinecheck=false, tableposition=bottom, justification=justified}
\begin{document}

\begin{figure}[t]
    \centering
    \subfloat[First figure]
    {%
        \label{fig.test1}%
        \includegraphics[clip,width=0.6\columnwidth]{example-image-a.png}}
    \vfill
    \subfloat[Second figure]
    {%
        \label{fig.test2}%
        \includegraphics[clip,width=0.6\columnwidth]{example-image-a.png}}
    \mycaption{I want to display this caption right below the left corner of the figure.}{Explanation blah blah..}
    \label{fig.test}
\end{figure}

\end{document}

If you do not want to align the caption with the left margin of the image, but with the y-axis of the image instead, one needs to add a little bit tinkering:

\documentclass[a4paper,11pt]{report}
\usepackage{import}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{caption}

\newcommand\mycaption[2]{\caption{\textbf{#1}\newline\footnotesize#2}}
\captionsetup{font=small, labelfont=bf, singlelinecheck=false, tableposition=bottom, justification=justified}
\begin{document}

\begin{figure}[t]
    \captionsetup[subfigure]{margin=0.5cm} % Add extra margin to the sub-captions
    \centering
    \subfloat[First figure]
    {%
        \label{fig.test1}%
        \includegraphics[clip,width=0.6\columnwidth]{example-image-a.png}}
    \vfill
    \subfloat[Second figure]
    {%
        \label{fig.test2}%
        \includegraphics[clip,width=0.6\columnwidth]{example-image-a.png}}
    \mycaption{I want to display this caption right below the left corner of the figure.}{Explanation blah blah..}
    \label{fig.test}
\end{figure}

\end{document}

I have added extra 0.5cm margin here, you need to adjust this value until the caption fits.

1
  • Thank you P.M. for the detailed explanation. Good to know about the unwanted spaces too!
    – yufiP
    Commented Feb 8, 2021 at 19:36

You must log in to answer this question.

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