I want to display two figures side by side but captions seem to overlap no matter the minipage width. Is there anyway to reduce caption size locally? Or make it respect margins?
Here is my code:
\documentclass[12pt,a4paper,openright,oneside]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{tikz}
\newcommand{\exedout}{
\begin{tikzpicture}
\path node (LL) {}
++ (0.8\textwidth, 0.4\textheight) node (UR) {}
(LL -| UR) node (LR) {}
(LL |- UR) node (UL) {};
\draw (LL) rectangle (UR) (LL) -- (UR) (UL) -- (LR);
\end{tikzpicture}
}
\begin{document}
\begin{figure}
\begin{minipage}{0.45\textwidth}
\exedout
\caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}%
\begin{minipage}{0.45\textwidth}
\exedout
\caption{Caption number two with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}
\end{figure}
\end{document}
Which outputs:
How can I fix this?
PD: How do I use the example images such as 'example-image-a' and so on that i have seen numerous times on this site?
Best Answer
Since you're using the
caption
package, it is easy to set thewidth
of the caption as you wish. You can add\captionsetup{width=0.4\textwidth}
, for example, to limit the width of the caption text to only0.4\textwidth
.Another important observation is that the
minipage
s have no space in-between. So, if you just add\hfill
between them, the problem totally disappears (assuming, of course, that the sum of the two widths is less than alinewidth
):