1

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: Caption 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}%
\addtolength{\float@cparwidth}{-1.0\float@capnamewd}%
\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):

enter image description here

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.

  • 1
    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. – Sigur 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. – Ablia Oct 20 '18 at 16:40
  • The floatrow package might help here. – Bernard 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. – John Kormylo 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. – Axel Sommerfeldt Oct 22 '18 at 8:04
1

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}

problem

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}

solution

  • Thank you! this is working perfectly! :) had to change the width for 0.5\textwidth, but still exactly what i needed. – Ablia 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. – Ablia 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. – John Kormylo Oct 23 '18 at 13:36
  • Technically, I should have used \columnwidth. – John Kormylo Oct 23 '18 at 13:42
0

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.

  • 1
    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. – Ablia 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. – johnymm 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. – Ablia Oct 22 '18 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.