0

I have the following code

\begin{figure}[h]
\begin{subfigure}[h]{0.4\linewidth}
\includegraphics[width=\linewidth]{Plots/scatterpng.png}
\end{subfigure}
\hfill
\begin{subfigure}[h]{0.65\linewidth}
\includegraphics[width=\linewidth]{Plots/lollipng.png}
\end{subfigure}%
\caption{\textbf{Search trends for cyber insurance in the US and in Germany}}
  \label{fig:1}
    \begin{minipage}{0.87\textwidth}\footnotesize
\emph{Note:} This figure was created scraping data from Google search trends. In the USA, the term cyber insurance was used whereas in Germany, the term cyber versicherung was used. The vertical lines have been added to show the occurence of significant events during that time period.   
\end{minipage}  
\label{f:3}
\end{figure}

I want to have both figures side by side. I also want to have a minipage/description that aligns neatly below the title of the figure.

If I keep the code as above, it is impossible to center the minipage-text below the title.

enter image description here

If I add \center to the code the minipage subtext is perfectly aligned below the title. However, the figures are then not side by side each other but on top of each other.

I can't fathom how to come up with a proper solution.

Any help would be highly appreciated

1
  • Why 0.87\textwidth? Anyway, you can center just the minipage using \centering\begin{minipage}... Apr 2, 2023 at 15:22

1 Answer 1

2

In this context, \linewidth is equal to \textwidth. You resize images to 0.4\linewidth and 0.65\linewidth, which adds up to 1.05\linewidth or 1.05\textwidth--your images exceed available page width by 5%. On top of that, LaTeX inserts one space after \end{subfigure} (see this answer). In this case the second subfigure is moved to the next line.

As to the description, add \centering before your description.

A remedy for the figures is (1) use widths that sum to 1\textwidth or less and (2) add % at the end of the fist line of \end{subfigure}%.

Below example places two figures next to each other with small gap and centres the description. I also added \captionsetup to change spaces around the caption.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}


\begin{document}
\begin{figure}[h]
  \captionsetup{position=bottom, aboveskip=3pt,belowskip=3pt}
  \centering
  \begin{subfigure}[h]{0.39\linewidth}
    \includegraphics[width=\linewidth]{Plots/scatterpng.png}
  \end{subfigure}%   <--- keep % here
  \hfill
  \begin{subfigure}[h]{0.59\linewidth}
    \includegraphics[width=\linewidth]{Plots/lollipng.png}
  \end{subfigure}
  \caption{\textbf{Search trends for cyber insurance in the US and in Germany}}\label{fig:1}

  \begin{minipage}{0.87\textwidth}\footnotesize
    \emph{Note:} This figure was created scraping data from Google search trends. In the USA, the term cyber insurance was used whereas in Germany, the term cyber versicherung was used. The vertical lines have been added to show the occurence of significant events during that time period.   
  \end{minipage}  
  \label{f:3}
\end{figure}
\end{document}

enter image description here

You must log in to answer this question.

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