# Captions of figures in minipage

I am trying to have two image on the same line. I found some solutions online which seems to work pretty well, and i've decided to use this one:

\begin{figure}[!ht]
\begin{minipage}[c]{8cm}
\centering
\includegraphics[width =\textwidth]{money_spend_on_cloud.png}
\caption{money spend on cloud}
\end{minipage}
\hfill
\begin{minipage}[c]{8cm}
\centering
\includegraphics[width=\textwidth]{WB-graph.jpg}
\caption{Cloud storage}
\end{minipage}
\end{figure}


The two figures are on the same page. However, i have only one caption, which takes the whole page (it's not limited to its minipage) and i don't understand why. It seems that the caption of first picture is somehow "under" the second caption and thus not visible, but since caption are on separate minipages it shouldn't be the case.

Plus, this code is used on many example and the captions are well placed :/

Can someone help me solve this? Here is the problem:

EDIT: as it works well on online example, i guessed it cames from my document class. I was rigth. I have those lines in my document class:

\newlength{\float@capnamewd}   % neu
\newlength{\float@cparwidth}   % neu
\newsavebox{\float@capnamebox} % neu
\renewcommand\floatc@ruled[2]{%
\savebox{\float@capnamebox}{\@fs@cfont #1\hspace*{1.5ex}}
\settowidth{\float@capnamewd}{\usebox{\float@capnamebox}}%
\setlength{\float@cparwidth}{\hsize}%
\usebox{\float@capnamebox}\parbox[t]{\float@cparwidth}{#2\par}}
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
\def\@fs@pre{}%
\def\@fs@post{\kern2.5pt\hrule height.1pt depth0pt\relax}%
\def\@fs@mid{\kern2pt\hrule height.1pt depth0pt \kern2.5pt}%
\def\@fs@cfont{\captionfont\bfseries}
\let\@fs@iftopcapt\iffalse}
\floatstyle{ruled}
\restylefloat{figure}
\restylefloat{table}


I have no idea what it means, but it's obviously about figures and captions. And when i put it as commentary, then my code for figures works well. This is what i get (and exactly what i wanted):

The caption format is not the same, but i don't care at all. However, i would like to understand what those lines in my document class are doing. Can someone explain me those lines? Maybe i don't have to put everything in commentary...

EDIT: so, trying to see what exactly in my wissdoc was problematic, i ended up putting only the line

\restylefloat{figure}


in commentary. So if i thought that all the lines before are defining a new float style, and then this line apply it to the figures. But this new float style is bad for me. However, when i put all the lines but this one in commentary, i still have the problem. The caption have the same format that in my second picture, but there's just the second one placed like in my first picture. I don't get it.

• It is not clear what you wish. Do you want: (i) 2 images with a single centered caption; (ii) 2 images with 2 captions centered below each one. Oct 20 '18 at 16:37
• well, i found this code on many tutos with an example above, it is working well. Plus, you can put a minipage in a figure but not a figure in a minipage, so i don't really have a choice...I don't want to use subfigures here. Those are two differents figures, i want them labelled as so with their own caption and not with subcation and global caption. Each image should have his own caption centered below it. Oct 20 '18 at 16:40
• The floatrow package might help here. Oct 20 '18 at 16:53
• See also tex.stackexchange.com/questions/403661/…. OTOH, if \@makecaption is defined in the document class, there is no \old@makecapton to use. You might try \caption@makecaption from the caption package. Oct 21 '18 at 15:38
• Are we talking about this wissdoc document class? tm.uka.de/~bless/latexhints.html If yes, the lines using the float package and re-defining the ruled float style are commented out since at least Mai 2012.
– user2574
Oct 22 '18 at 8:04

First, I used floatrow to emulate your document class.

\documentclass{article}
\usepackage{floatrow}
\floatsetup{style=ruled,capposition=bottom}
\usepackage{graphicx}

\begin{document}
\begin{figure}[!ht]
\begin{minipage}[c]{0.45\textwidth}
\centering
\includegraphics[width =\textwidth]{example-image-a}
\caption{money spend on cloud}
\end{minipage}
\hfill
\begin{minipage}[c]{0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{example-image-b}
\caption{Cloud storage}
\end{minipage}
\end{figure}

\end{document}


Then I used paracol to achieve the desired effect while maintaining the intention of the anal retentive who designed the thing. Unlike multicol, paracol supports floats. You might want to use \afterpage (afterpage package) if this causes a page break.

\documentclass{article}
\usepackage{floatrow}
\floatsetup{style=ruled,capposition=bottom}
\usepackage{graphicx}
\usepackage{paracol}% support floats
\globalcounter{figure}

\begin{document}
\begin{paracol}{2}
\begin{figure}
\centering
\includegraphics[width =\columnwidth]{example-image-a}
\caption{money spend on cloud}
\end{figure}
\switchcolumn
\begin{figure}
\centering
\includegraphics[width=\columnwidth]{example-image-b}
\caption{Cloud storage}
\end{figure}
\end{paracol}

\end{document}


• Thank you! this is working perfectly! :) had to change the width for 0.5\textwidth, but still exactly what i needed. Oct 23 '18 at 13:01
• Just a question: why do i have to add the \globalcounter{figure} ? I've seen that without it, the figure number isn't increasing (also in this example, both figures are Figure 1) but i don't understand why. Oct 23 '18 at 13:13
• One of the features of paracol is to allow separate counters in the two columns, since it is used mostly for translations. \globalcounter uses the same counter in both columns. Oct 23 '18 at 13:36
• Technically, I should have used \columnwidth. Oct 23 '18 at 13:42

I believe the \caption command does no recognize the minipage environment, but works only once for the figure environment. Hence the one caption in your example.

Instead, try using the \captionof command from the caption package. In your example, this is a easy fix by using:

....rest of preamble....
\usepackage{caption}
\begin{document}
\begin{figure}[!ht]
\begin{minipage}[c]{8cm}
\centering
\includegraphics[width =\textwidth]{money_spend_on_cloud.png}
\captionof{figure}{money spend on cloud}
\end{minipage}
\hfill
\begin{minipage}[c]{8cm}
\centering
\includegraphics[width=\textwidth]{WB-graph.jpg}
\captionof{figure}{Cloud storage}
\end{minipage}
\end{figure}
\end{document}


That should give you the caption you want for each figure.

• No. this solution gives exactly the same output as mine, which mean only one caption when my wissdoc is used, and two correct caption when i put the wissdoc part in commentary. Plus, as said, my code is on many tuto with an example, it is suppose to work well. The only problem here is my wissdoc document class, which is changing something but i don't really understand what. Oct 21 '18 at 8:05
• Are you using a custom document class? I'm not familiar with this "wissdoc," but if it's causing the issue then I wouldn't be able to know until I saw it. Otherwise the code above should work. Oct 21 '18 at 13:56
• i use wissdoc as document class, and the wissdoc code which is the cause of my problem is also in my question. I didn't post all the wissdoc (which can be found on GIT), but only the part related with figures. Oct 22 '18 at 12:00