2

I have been trying to put 2 figures next to each other, however i have noticed that the spacing between caption is non existing,

\begin{figure}
\centering
 \begin{minipage}[b]{0.52\textwidth}
  \includegraphics[width=1\textwidth]{Figures/badtimes2.eps}
  \caption{Stock index, 2nd half, shaded areas highlight the bad time}
 \end{minipage}%
 \begin{minipage}[b]{0.52\textwidth}
  \includegraphics[width=1\textwidth]{Figures/decr-sent.eps}
  \caption{Sentiment index. Shaded areas highlight the periods of increasing and decreasing sentiment.}
 \end{minipage}
\end{figure}

spacing

can someone help me fix this problem? Thanks in advance

6
  • thank you so much guys, that worked magic! Commented Apr 7, 2019 at 2:21
  • Even better {dimexpr 0.5\textwidth-0.5\columnsep} Commented Apr 7, 2019 at 17:00
  • Hi, John! could u be more specific of where exactly to put this command? thank you in advance Commented Apr 7, 2019 at 23:12
  • @FilipPierzgalski He suggest you uses \begin{minipage}[b]{\dimexpr 0.5\textwidth-0.5\columnsep} instead of \begin{minipage}[b]{0.45\textwidth} in the two minipage (and don't forget to use \hfill between the two minipage environments as suggested by egreg). This code create a gap of exactly one column sep between the two pictures (the same gap as in a default two-column document).
    – quark67
    Commented Apr 8, 2019 at 2:24
  • I have included a option with subfigure. It might be better to work with in some cases and might help with your question.
    – Andre
    Commented Apr 9, 2019 at 13:40

2 Answers 2

1

sum of your minipage width is larger than text width (0.52\textwidth + 0.52\textwidth = 1.04 \textwidth. at least you need to reduce it to 1\textwidth or as is sugested in comment below your questionreduceminipage` width to value smaller than 0.5. For example 0.48 can be good value.

beside use of minipage it my be worth to consider tabularx instead them:

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

\begin{document}
    \begin{figure}
\centering
 \begin{minipage}[b]{0.48\textwidth}
  \includegraphics[width=1\textwidth]{Figures/badtimes2.eps}
  \caption{Stock index, 2nd half, shaded areas highlight the bad time}
 \end{minipage}\hfill
 \begin{minipage}[b]{0.48\textwidth}
  \includegraphics[width=1\textwidth]{Figures/decr-sent.eps}
  \caption{Sentiment index. Shaded areas highlight the periods of increasing and decreasing sentiment.}
 \end{minipage}
    \end{figure}

    \begin{figure}
\begin{tabularx}{\linewidth}{@{}XX@{}}
  \includegraphics[width=\linewidth]{Figures/badtimes2.eps}
  \caption{Stock index, 2nd half, shaded areas highlight the bad time}
 &
  \includegraphics[width=\linewidth]{Figures/decr-sent.eps}
  \caption{Sentiment index. Shaded areas highlight the periods of increasing and decreasing sentiment.}
 \end{tabularx}

enter image description here

above image belong to your approach (with corrected minipage width), bottom image is result at use of tabularx. in test i use article document class, since you not provide any information about your document layout˙and used document class.

1

Have you tried subfigure, with the package subcaption? Here is the code:

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}[ht]
    \centering
    \begin{subfigure}[t]{0.49\linewidth}
        \includegraphics[width=1\linewidth]{example-image-a}
        \caption{Stock index, 2nd half, shaded areas highlight the bad time}
    \end{subfigure}
    \hfill
    \begin{subfigure}[t]{0.49\linewidth}
        \includegraphics[width=1\linewidth]{example-image-b}
        \caption{Sentiment index. Shaded areas highlight the periods of increasing and decreasing sentiment.}
    \end{subfigure}
\end{figure}

\end{document}

I have included a small space between the figures with \hfill, following this answer. You can remove it if you prefer the figures closer to each other.

The output is this: enter image description here

You must log in to answer this question.

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