Search code examples
latexoverleaf

Merge subtitle of two figures Overleaf


I am trying to add to my overleaf document two groups of two figures (the first two for France, the second two for Italy) that share a caption below. However, everything I tried either only keeps the first caption as the title for all the figures or does not encompass the two charts. How can I create a caption that only affects the two previous figures?

My code is as follows:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage[labelfont=bf, justification=justified, singlelinecheck=false]{caption}
\captionsetup[figure]{labelsep=period,name=FIGURE,font=custom}
\usepackage[tablename=TABLE,font=custom,labelsep=period]{caption}
\usepackage{afterpage}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{wasysym}
\usepackage{rotating}
\usepackage{amsmath,amssymb}
\usepackage[flushleft]{threeparttable}
\usepackage{array,booktabs,makecell}
\usepackage{caption}
\usepackage{changepage}
\setcounter{tocdepth}{1}
\usepackage{subcaption}


\begin{document}


\begin{figure}[H]
\centering
\begin{subfigure}[b]{0.5\textwidth}
   \centering
   \includegraphics[height=0.5\textwidth]{example-image.pdf}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
   \centering
   \includegraphics[height=0.5\textwidth]{example-image.pdf}
\end{subfigure}
\caption{France charts}
\begin{subfigure}[b]{0.5\textwidth}
   \centering
   \includegraphics[height=0.5\textwidth]{example-image.pdf}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
   \centering
   \includegraphics[height=0.5\textwidth]{example-image.pdf}
\end{subfigure}
\caption{Italy charts}
\end{figure}

\end{document}

Thank you very much!

enter image description here


Solution

  • There are two major errors in the code:

    1. If you want to use the [H] floating specifier, you must load the float package

    2. font=custom will produce errors


    You can use \captionsetup{justification=centering} to switch back to centred captions for your figure:

    \documentclass[12pt]{article}
    \usepackage{amsmath}
    \usepackage{setspace}
    \usepackage[labelfont=bf, justification=justified, singlelinecheck=false]{caption}
    \captionsetup[figure]{labelsep=period,name=FIGURE}
    \usepackage[tablename=TABLE,labelsep=period]{caption}
    \usepackage{afterpage}
    \usepackage{longtable}
    \usepackage{graphicx}
    \usepackage{bbding}
    \usepackage{pifont}
    \usepackage{wasysym}
    \usepackage{rotating}
    \usepackage{amsmath,amssymb}
    \usepackage[flushleft]{threeparttable}
    \usepackage{array,booktabs,makecell}
    %\usepackage{caption}
    \usepackage{changepage}
    \setcounter{tocdepth}{1}
    \usepackage{subcaption}
    
    
    \usepackage{float}
    
    \begin{document}
    
    
    \begin{figure}[H]
    \centering
    \captionsetup{justification=centering}
    \begin{subfigure}[b]{0.5\textwidth}
       \centering
       \includegraphics[height=0.5\textwidth]{example-image.pdf}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
       \centering
       \includegraphics[height=0.5\textwidth]{example-image.pdf}
    \end{subfigure}
    \caption{France charts}
    \begin{subfigure}[b]{0.5\textwidth}
       \centering
       \includegraphics[height=0.5\textwidth]{example-image.pdf}
    \end{subfigure}%
    \begin{subfigure}[b]{0.5\textwidth}
       \centering
       \includegraphics[height=0.5\textwidth]{example-image.pdf}
    \end{subfigure}
    \caption{Italy charts}
    \end{figure}
    
    \end{document}
    

    enter image description here