4

I need to have figures with several subfigures . In some cases, the subfigures of a figure have to go to the next page. For this purpose, I have to use \continuedFloat but then the figure number of image remain same (or sometimes completely weird).

I have asked this question before here and somebody also asked similar problem here but the solutions provided to both the questions did not work for me. Therefore, I am posting a new question with minimal working example.

IMPORTANT UPDATE: Just now I realized that if I remove the line \usepackage[hidelinks]{hyperref} then, everything works fine. But if I keep that line of code then, the figure number of both the figures remain same.

My code (MWE):

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[a4paper, width=425.196850394pt, top=70.866141732pt,bottom=70.866141732pt]{geometry}
\usepackage{tabu}
\usepackage[hidelinks]{hyperref}
\usepackage{float}  
\raggedbottom                    
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}%%%SO for th table form of images
\usepackage[caption = true,font=normalsize]{subfig}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Document Begins from here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother


\chapter{Introduction}
This chapter is about the problem of wrong figure numbers.

%%%----------------------------------------------Normal Figure----------------------%%%%%%%%%%
        \begin{figure}[h]
        \centering
        \includegraphics[scale=0.5]{example-image}
        \caption{Figure on a single page.}
        \end{figure}

%%%---------------------------------------------Two page Figure---------------------%%%%%%%%%%
\begin{figure}[!ht]

    \subfloat[]{\includegraphics[scale=1]{example-image}} \\
    \subfloat[]{\includegraphics[scale=1]{example-image}} \\
    \phantomcaption
\end{figure}
%%mages on the new page
\begin{figure}[]
\ContinuedFloat
    \subfloat[]{\includegraphics[scale=1]{example-image}} \\    
\caption{Figure on two pages}
\label{image}
\end{figure}

%%%--------------Tabular Figure --------%%%%%%%%%%
\begin{figure}

%%Original image
\subfloat[Original image]{%
\begin{minipage}{\linewidth}
     \centering
      \begin{tabularx}{\linewidth}{YYYY}
          \includegraphics[scale=1]{example-image}    \\
    \end{tabularx}
\end{minipage}}\par\medskip

%% First Layer
\subfloat[Third layer]{%
\begin{minipage}{\linewidth}
    %\centering
    \begin{tabularx}{\linewidth}{YYYYY}
        \includegraphics[scale=0.5]{example-image}
        &\includegraphics[scale=0.5]{example-image}  \\ 
        First image & Second image
    \end{tabularx}
\end{minipage}}
\phantomcaption
\end{figure}
%%%%%%%%%%%%%%%%%Figure continued%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[ht]
\ContinuedFloat
 %%Second Layer
\subfloat[Forth layer]{%
\begin{minipage}{\linewidth}
    %\centering
    \begin{tabularx}{\linewidth}{YYYYY}
        \includegraphics[scale=0.5]{example-image}
        &\includegraphics[scale=0.5]{example-image}  \\ 
        First image & Second image
    \end{tabularx}
\end{minipage}}
\caption{Figure using Tables}
\label{image}
\end{figure}


\end{document}

No Solution yet:

  • The solution provided to my question says to use \phantomcaption and set caption=true which I have already done but still the figure number of both the figures are same.

  • The solution provided to other question is also similar and that did not work for me either.

  • I think subfig has some issues with hyperref, is switching to subcaption an option? – Torbjørn T. Sep 3 '15 at 9:06
  • @TorbjørnT. : By switching to it, it throws an that Undefined control sequence \subfloat. And, changing the whole structure will be a problem as this is just a MWE of whole big file. – skm Sep 3 '15 at 9:10
  • Yes, switching package does require switching syntax for all subfloats, which is a downside. The upside is that it works. – Torbjørn T. Sep 3 '15 at 9:12
  • @TorbjørnT. : In my thesis file (quite big), the figure number were quite weird. It was like 5.1, 5.2 5.3 5.2 5.1 5.0. And after removing hyperref, it becomes 5.1, 5.2 5.3 5.3 5.3 5.3. So, the problem persists even after removing hyperref. – skm Sep 3 '15 at 9:14
  • @TorbjørnT. : Ok, please provide the example of solving this problem using subcaption. I will try to make changes in my original file if it helps – skm Sep 3 '15 at 9:44
2

It may be possible to make this work with subfig as well, but here is an example that uses subcaption instead. It provides, among other things, a subfigure environment and a subcaption command. The former is a minipage-like environment, used as

\begin{subfigure}{\linewidth}
\includegraphics{example-image}
\caption{This is a sub-caption.}
\end{subfigure}

The latter is used instead of the normal \caption, and makes sub-captions instead. In general, this should only be used within a group or environment. The manual shows an example with minipages, in the below code I just added a brace pair around it and the graphic.

With the below code you get figures 1.1, 1.2, 1.3, 1.4 as expected.

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[a4paper, width=425.196850394pt, top=70.866141732pt,bottom=70.866141732pt]{geometry}
\usepackage{float}  
\raggedbottom                    
\usepackage{subcaption}
\usepackage[hidelinks]{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Document Begins from here %%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother


\chapter{Introduction}
This chapter is about the problem of wrong figure numbers.

%%%----------------------------------------------Normal Figure----------------------%%%%%%%%%%
\begin{figure}
\centering
\includegraphics[scale=0.5]{example-image}
\caption{Figure on a single page.}
\end{figure}

%%%---------------------------------------------Two page Figure---------------------%%%%%%%%%%
\begin{figure}
\begin{subfigure}{\linewidth}
\includegraphics[scale=1]{example-image}
\caption{}
\end{subfigure}

{\includegraphics[scale=1]{example-image}
\subcaption{}}
\end{figure}
\begin{figure}
\ContinuedFloat
\begin{subfigure}{\linewidth}
\includegraphics[scale=1]{example-image}
\caption{}
\end{subfigure}
\caption{Figure on two pages}
\end{figure}

% Normal figure
\begin{figure}
\centering
\includegraphics[scale=0.5]{example-image}
\caption{Figure on a single page.}
\end{figure}

% continued floats
\begin{figure}
\begin{subfigure}{\linewidth}
\includegraphics[scale=1]{example-image}
\caption{}
\end{subfigure}

{\includegraphics[scale=1]{example-image}
\subcaption{}}
\end{figure}
\begin{figure}
\ContinuedFloat
\begin{subfigure}{\linewidth}
\includegraphics[scale=1]{example-image}
\caption{}
\end{subfigure}
\caption{Figure on two pages}
\end{figure}
\end{document}

Side by side figure

Personally I wouldn't use a tabular(x) at all for that case, but if you prefer it, just place the tabularx environment a \caption inside a subfigure environment, i.e.

\begin{subfigure}{\linewidth}
\begin{tabularx}{\linewidth}{YY}
\includegraphics{1} & \includegraphics{2} \\
First & Second
\end{tabularx}
\caption{Third layer}
\end{subfigure}

Here is a different suggestion:

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage[a4paper, width=425.196850394pt, top=70.866141732pt,bottom=70.866141732pt]{geometry}
\usepackage{subcaption}

\usepackage[hidelinks]{hyperref}
\usepackage{float}  
\raggedbottom                    


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Document Begins from here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother


\chapter{Introduction}
This chapter is about the problem of wrong figure numbers.

\begin{figure}
\centering
\includegraphics[scale=0.5]{example-image}
\caption{Figure on a single page.}
\end{figure}

%%%---------------------------------------------Two page Figure---------------------%%%%%%%%%%
\begin{figure}[!ht]
\begin{subfigure}{\linewidth}
\centering
\includegraphics{example-image}
\caption{}
\end{subfigure}
\begin{subfigure}{\linewidth}
\centering
\includegraphics{example-image}
\caption{}
\end{subfigure}
\end{figure}
%%mages on the new page
\begin{figure}
\ContinuedFloat
\begin{subfigure}{\linewidth}
\centering
\includegraphics{example-image}
\caption{}
\end{subfigure}
\caption{Figure on two pages}
\label{image}
\end{figure}

%%%--------------Tabular Figure --------%%%%%%%%%%
\begin{figure}
%%Original image
\begin{subfigure}{\linewidth}
\centering
\includegraphics{example-image}
\caption{Original image}
\end{subfigure}
\par\medskip
\begin{subfigure}{\linewidth}
\centering
\begin{minipage}{0.47\linewidth}
\centering
\includegraphics[scale=0.5]{example-image}

First image
\end{minipage}\hfill
\begin{minipage}{0.47\linewidth}
\centering
\includegraphics[scale=0.5]{example-image}

Second image
\end{minipage}
\caption{Third layer}
\end{subfigure}
\end{figure}
%%%%%%%%%%%%%%%%%Figure continued%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[ht]
\ContinuedFloat
 %%Second Layer
\begin{subfigure}{\linewidth}
\centering

\begin{minipage}{0.47\linewidth}
\centering
\includegraphics[scale=0.5]{example-image}

First image
\end{minipage}\hfill
\begin{minipage}{0.47\linewidth}
\centering
\includegraphics[scale=0.5]{example-image}

Second image
\end{minipage}
\caption{Fourth layer}
\end{subfigure}
\caption{Figure using Tables}
\label{image}
\end{figure}


\end{document}
  • thanks. I have updated my question. Actually, I have to put figures using table also. I have provided the third figure too using table in my MWE. Please tell me how can I use subcaption in that table environment – skm Sep 3 '15 at 10:33
  • @skm Just put the table in a subfigure environment? Or should First image and Second image be subcaptions? – Torbjørn T. Sep 3 '15 at 10:48
  • thanks, actually the tabular environment is not necessray for this example but in my original file, I need to have four image in a single row, I need to provide them indivisual names and I need to group them. For that case, use of tabular enviornment becomes necessary. Anyways, thanks for your suggestion – skm Sep 3 '15 at 12:38

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.