# Two independent figures side by side, problem with caption size

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?

• Concerning the usage of example-image-a: If you have the mwe package installed on your system, you should simply be able to use it like any other image name, just do \includegraphic{example-image} Mar 24, 2017 at 21:40

Since you're using the caption package, it is easy to set the width 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 only 0.4\textwidth.

\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}
\captionsetup{width=0.4\textwidth}
\begin{minipage}{0.45\textwidth}\centering
\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}\centering
\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}


Another important observation is that the minipages 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 a linewidth):

\begin{figure}
\begin{minipage}{0.45\textwidth}\centering
\exedout
\caption{Caption number one with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}%
\hfill
\begin{minipage}{0.45\textwidth}\centering
\exedout
\caption{Caption number two with enough text to overlap with caption number two bla... bla...bla... bla...bla... bla...}
\end{minipage}
\end{figure}


Use floatrow: you have control on the width of the floatboxes with the optional argument of \ffigbox (or \tabbox for tables):

\documentclass[12pt,a4paper,openright,oneside]{article}
\usepackage{graphicx}
\usepackage{caption, floatrow}
\usepackage{tikz}

\newcommand{\exedout}{
\begin{tikzpicture}
\path node (LL) {}
++ (0.8\linewidth, 0.4\textheight) node (UR) {}
(LL -| UR) node (LR) {}
(LL |- UR) node (UL) {};
\draw (LL) rectangle (UR) (LL) -- (UR) (UL) -- (LR);
\end{tikzpicture}
}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}

\begin{document}

\begin{figure}