0

I am writing my thesis in B5 format in Latex. In the main text, I can handle floats of the figures quite OK. But in the supporting information part, I have massive amount of images (images only under different sections/subsections) which I would like to place 2 images on one page. But after compiling, I am getting one image on a single page which increases the total number of pages heavily.

I have to use [H] from the float package because otherwise images appears random places and nothing placed under section/subsection names.

I have also tried something like

\documentclass[10pt,fleqn]{phdthesis}%,makeidx

\makeatletter
\renewenvironment{thebibliography}[1]
     {
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\makeatother

%%% For an A4 format, use there options instead
%\documentclass[12pt,makeidx]{phdthesis}
%\usepackage{a4wide}

\newcommand{\mypm}{\mathbin{\smash{%
\raisebox{0.35ex}{%
            $\underset{\raisebox{0.5ex}{$\smash -$}}{\smash+}$%
            }%
        }%
    }%
}

%%% Fonts, uncomment only one option %%%
%\usepackage{utopia}
%\usepackage{charter}
%\usepackage{palatino}
%\usepackage{newcent}
%\usepackage{avant}
\usepackage{pifont}
%\usepackage{mathpple}
%\usepackage{mathptmx}
\usepackage{multicol}
\usepackage{flafter}

%%% If you want to use MakeIndex to create automatically
% an index, uncomment these lines
\usepackage{makeidx}     % only with Latex2e
\makeindex

% Other packages
%\usepackage{fancyheadings}
% \usepackage{subfig}
%\usepackage[abbr]{harvard}
\usepackage{fancyhdr}
\usepackage{amsmath,dsfont}
\usepackage{amssymb,mathabx}
\usepackage{epsfig}
\usepackage[figbotcap]{subfigure}
\usepackage{graphics}
\usepackage{float}
\usepackage{here}
\usepackage[super,numbers,sort&compress]{natbib}  %coma
\renewcommand\bibsection{\section{\refname}}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{comment}
\usepackage{captionhack}
\usepackage{epigraph}
\usepackage{array,multirow,nicefrac}
\usepackage{appendix}
\usepackage{acronym}
\usepackage[chapter]{algorithm}
\usepackage{algorithmic}
\usepackage{mathtools}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{csquotes}
\usepackage{notes2bib}
\usepackage{siunitx}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{mciteplus}
\usepackage{longtable}

%----------------------------------------------------------------------------------------------------------
\makeatletter

\newcommand*\mycommand[1]{\texttt{\emph{#1}}}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\renewcommand{\mcitesubrefform}{\textsuperscript{\arabic{mcitebibitemcount}\alph{mcitesubitemcount}}}
\makeatother



%----------------------------------------------------------------------------------------------------------
% \usepackage{showframe}

\usepackage{lscape}
\usepackage[table]{xcolor}

\usepackage{wrapfig}

\usepackage{pstricks,pst-node}
% \usepackage{pstricks-add}%pst-char,,pst-text,ae,pst-grad,pst-slpe
\usepackage{fancybox}
%\usepackage[dvips,margin=1cm]{geometry}
% \usepackage{lmodern,pst-node}
\usepackage{psfrag}


% \renewcommand{\thesubfigure}{} 

\usepackage{float,afterpage,dblfloatfix}%stfloats
% dblfloatfix fixes two floatpages after each other
    % Alter some LaTeX defaults for better treatment of figures:
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    %   General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9}    % max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better was 4
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07}  % allow minimal text w. figs
%   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7}  % require fuller float pages was 0.7
    % N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7}   % require fuller float pages 0.7

\makeatletter
\def\zaptype#1{%
\listsubcaptions % Finish the last set of sub-floats before
\def\@captype{#1}}% switching to another float type.
\makeatother

%%% Path to the directorz containing the graphics and figures 
\graphicspath{{./pics/},{./pics/chapter_2/},{./pics/chapter_3/},{./pics/chapter_4/},{./pics/chapter_5/},{./pics/chapter_6/}
,{./pics/chapter_7/},{./pics/chapter_8/},{./pics/chapter_9/}}
\usepackage{ifpdf}
\ifpdf
\graphicspath{{./png/}}
\DeclareGraphicsExtensions{.png}
\else
  \DeclareGraphicsExtensions{{.eps},{.epsi}}%,{.ps}
\fi
%%% General page formatting
\renewcommand{\textfraction}{0.01}
\renewcommand{\topfraction}{0.99}
\renewcommand{\floatpagefraction}{0.99}
\renewcommand{\bottomfraction}{0.99}

\newenvironment{Abstract}
{\begin{center}\textbf{Abstract}%
 \end{center} \small \it \begin{quote}}
{\end{quote}}

% Macro for 'List of Symbols', 'List of Notations' etc...
\def\listofsymbols{\input{symbols} \clearpage}
\def\addsymbol #1: #2#3{$#1$ \> \parbox{4.6in}{#2 \dotfill \pageref{#3}}\\}
\def\newnot#1{\label{#1}} 


\pdfcompresslevel=3

\typeout{Dissertation}

\usepackage{hyperref}
%\usepackage{multibib}%[resetlabels]
% \def\@mb@citenamelist{cite,citep,citet,citealp,citealt,footcite,nocite}

% Initialize each paper type for which you need a bibliography.
% Just a dummy parameter is necessary.
% \newcites{p}{Publications}
%\newcites{journal,conf,techreport,submitpaper}{Journal Papers,Conference Papers,Technical Reports, Submitted Papers}%Journal Papers

\DeclareSIUnit\molar{\mole\per\cubic\deci\metre}
\DeclareSIUnit\Molar{\textsc{m}}

%%% To compile only one or some chapters, use the following
%   command 
% \includeonly{chapter1,chapter2,chapter3,chapter4,appendix_A}
%\includeonly{thesis_acknowledgements,chapter2,chapter3}
%\includeonly{chapter2}

% Morerow Comments
% \newcommand{\comment}[1]{{}} 


% correct bad hyphenation here
% TODO hyphenation
%\usepackage{hyphenat}
%\hyphenation{qua-dra-tic SRBCT pre-ser-va-tion Min-kow-ski a-dapt-ive de-ri-va-tive pat-ches pre-serv-ing re-sul-ting Em-bedd-ing 
%where-by uni-form de-ri-va-ti-ves con-ti-nu-ous-ly wille-keurige voor-ge-steld}
% solve hyphenation that contain a dash like electromagnetic-endioscopy: electromagnetic\hyp{}endioscopy
% high\hyp{}dimensional

% \usepackage{scrwfile}
% \usepackage{xy}%etex
% \xyoption{all} 

%%% Begining of the document 
\begin{document}

\subsection{Section Name}
    \begin{figure}[H]
    \includegraphics[width=\linewidth]{images1.png}
    \caption{caption 1}
    \label{fig1}

    \includegraphics[width=\linewidth]{images2.png}
    \caption{caption 2}
    \label{fig2}
    \end{figure}

    \begin{figure}[H]
    \includegraphics[width=\linewidth]{images3.png}
    \caption{caption 3}
    \label{fig3}

    \includegraphics[width=\linewidth]{images4.png}
    \caption{caption 4}
    \label{fig4}
    \end{figure}

\end{document}

instead of

\subsection{Section Name}
\begin{figure}[H]
\includegraphics[width=\linewidth]{images1.png}
\caption{caption 1}
\label{fig1}
\end{figure}

\begin{figure}[H]
\includegraphics[width=\linewidth]{images2.png}
\caption{caption 2}
\label{fig2}
\end{figure}

\begin{figure}[H]
\includegraphics[width=\linewidth]{images3.png}
\caption{caption 3}
\label{fig3}
\end{figure}

\begin{figure}[H]    
\includegraphics[width=\linewidth]{images4.png}
\caption{caption 4}
\label{fig4}
\end{figure}

But it is not really useful if I need to add something afterwards (if I add a figure in between I have to redo everything again). And also if I include two images in a single \begin{figure}, I get a blank page before it.

Here is a screenshot what I get: enter image description here

and what I want: enter image description here

  • if you use H then the entire float has no positioning logic applied at all, it's just as positioned as if it was a big X at that point, so basically you can have as many H floats on a page as you want if they fit. It's not possible to run your code but presumbably the images are (or at least tex things they are) too big to fit (allowing for space between them and the page number etc. If you use example-image (which is available for such tests) and made a real test document someone could suggest how to make the images fit – David Carlisle Feb 24 '18 at 12:14
  • unrelated but don't load here (it just loads float) don't load amsmath (twice) as it's loaded by mathtools, don't load epsfig (ever:-) use graphicx don't load graphics (included by at least epsfig or rotating or graphicx or psfrag) you specify multiorow twice – David Carlisle Feb 24 '18 at 12:22
  • I am using the following template for the thesis in general: rug.nl/research/intelligent-systems/latexresources/… – Yigit Altay Feb 24 '18 at 12:35
  • it is best to make a small example that you add inline to your question (it should only need article class float.sty and some floats using example-image with heights forced to demonstrate your issue. – David Carlisle Feb 24 '18 at 12:38
  • As a rule, avoid templates, and never use a package unless you know what it does. – John Kormylo Feb 24 '18 at 16:47
2

To place two images in a page, [H] is just the worst option as this avoid floating the two images to the right nearly point (most probably the beginning of the next page) without leaving huge wasting spaces.

You really only need take care of tree things to avoid this:

(1) Obviously, always avoid [H] (at least for this objective).

(2) Place the [p] option alone (or combined with t and b) whenever it is needed (convenient,permissible) to group floats.

(3) Take care that the height of the two images plus the height of the two captions and some more (because \floatsep and \textfloatsep if there are also some text) is no more that the total height of text. If so, reduce the image size, the captions or both.

Alternatively you can put several images in a a float, but this not save you of (3), only make the [tbp] options mostly irrelevant (as far as the height of the float is near of hte the height of the whole text area). The only advantage of this approach is force join images at any cost (even when they do not fit at all in the page) but precisely for this reason usually will be better use two float and with the appropriate option/s:

This MWE try to explain this with some examples:

mwe

\documentclass{article}
\usepackage{geometry,lipsum,graphicx}

% Just to simplify the posterior code
\def\image#1{\centering\includegraphics
[width=\linewidth,height=.34\textheight,keepaspectratio]{#1}}
\def\wideimage#1{\centering\includegraphics
[width=\linewidth,height=\textheight,keepaspectratio]{#1}}
\def\captionlipsum{\caption{\protect\lipsum[2]}}

\begin{document}
\lipsum[1] % dummy text

% [p] option is good if you want two images in one page
\begin{figure}[p]\image{example-image}\captionlipsum\end{figure}

% option here is superfluous (except if you use also "b" or "t") 
\begin{figure}[tbp]\image{example-image-a}\captionlipsum\end{figure}

% [p] option still works! 
\begin{figure}[tbp]\image{example-image-1x1}\captionlipsum\end{figure}\lipsum[4]
\begin{figure}[tbp]\wideimage{example-image-16x9}\caption{ssss}\end{figure}\lipsum[5]
\lipsum[3]

% options here agian is superfluous 
\begin{figure}\wideimage{example-image-9x16}\captionlipsum\end{figure}\lipsum[5]

% Images too big per only one page  
% Use [t], [b] or [tp] but not [p] if you want avoid a centered image without text around
% (maybe not a bad idea after all ...) 

\begin{figure}[tb!] \wideimage{example-image-16x9}\captionlipsum\end{figure}\lipsum[5]
\begin{figure}[tb!]\wideimage{example-image}\captionlipsum\end{figure}

\lipsum[3]

% Two images in a float to maintain together. Not a good idea in this case ....    
\begin{figure}
\wideimage{example-image-a}\captionlipsum\vspace{\floatsep}
\wideimage{example-image-b}\captionlipsum\end{figure}
\lipsum[5]

% ... unless you take care of the image size
\begin{figure}
\image{example-image-a}\captionlipsum\vspace{\floatsep}
\image{example-image-b}\captionlipsum\end{figure}
\lipsum[6-20]

\end{document}
  • I mostly agree with you, but: If you want to have control over where the images are put, don't use figure at all. So it might be best to not use figure (though your tips on positioning are all correct and good if one uses figure). – Skillmon likes topanswers.xyz Feb 24 '18 at 15:14
  • @Skillmon As far I understood, in this case the problem is not maintain images together in an exact position of text , but in the same page, completely filled with that images. Whereas for the first is enough put aside the floats (but using a package for the captions) for the second I do not see why to do that. – Fran Feb 24 '18 at 15:47

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.