0

I have a weird layout problem in LaTeX, in which, for some reason, floats that can clearly fit on one page, are spread out on two pages, even when using big vspaces.

Layout problem

The attached picture shows the compiled result of the following code:

\begin{figure}[ht]
\centering
\includegraphics[width=.85\textwidth]{baseline_sensor2}
\caption{Test ID S2.1 - sensor 2}
\end{figure}

\vspace{-5cm}
\begin{figure}[ht]
\centering
\includegraphics[width=.85\textwidth]{baseline_sensor3}
\caption{Test ID S2.1 - sensor 3}
\end{figure}

I've had this problem on several occasions with this template. Weirdly enough, if I do manage to reduce the size sufficiently to gather the floats on one page, I can still add some text on that same page, without messing up the layout. Even when the size reduction is 1 % different from what doesn't fit on the page.

This is my preamble.

\documentclass[a4paper,oneside,10pt]{report}

%% Formatting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[USenglish]{babel} %francais, polish, spanish, ...
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern} %Type1-font for non-english texts and characters

%% Packages for Graphics & Figures %%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx} %%For loading graphic files
\usepackage{subfig}
\graphicspath{{images/}}
\usepackage[headheight=70pt,margin=1.0in,top=1.5in,bottom=1.0in,showframe=false]{geometry}

%% Packages for tables:
\usepackage{tabularx} % Include for better table functionality
\usepackage{tablefootnote} % Include to allow for footnotes in tables
\usepackage{multirow} % Write one entry for multiple rows and columns in tables
\usepackage{booktabs} % Insert divider rules in tables

%% Color Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[table,xcdraw]{xcolor}
\setlength{\arrayrulewidth}{0.4mm} % witdh of lines
\setlength{\tabcolsep}{8pt} % width of each row
\definecolor{green}{rgb}{0,0.59765625,0.59765625}
\definecolor{red}{rgb}{0.6875,0.08984375,0.12109375}
\definecolor{blue}{rgb}{0.25390625,0.41015625,0.87890625} 
\definecolor{gray}{rgb}{0.9140625,0.9140625,0.9453125}
\definecolor{gray2}{rgb}{0.75,0.75,0.75}
\definecolor{stoneblack}{rgb}{0.234375  ,  0.2734375 ,  0.29296875}
\definecolor{snow}{rgb}{0.99609375  ,  0.99609375 ,  0.99609375}
\definecolor{sgreen}{rgb}{0,0.59765625,0.59765625}
\definecolor{stonelight}{rgb}{0.67578125,0.7421875,0.79296875}
\definecolor{yellow}{rgb}{0.99609375,  0.72265625,  0}
\definecolor{black}{rgb}{0  ,  0 ,  0}
\definecolor{red2}{rgb}{0.68359375,  0.13671875,  0.37109375}

%% Math Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{xfrac}
\usepackage{siunitx} % Allows for easy unit input

%% Line Spacing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage{setspace}
%\singlespacing        %% 1-spacing (default)
%\onehalfspacing       %% 1,5-spacing
%\doublespacing        %% 2-spacing

%% Other Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[pdftex,bookmarks=true,hidelinks]{hyperref} % Allows for inserting urls with \url{}
\usepackage{url}
\usepackage{bookmark}
\bookmarksetup{depth=3} 
\usepackage[absolute,overlay]{textpos} % Used for textblock on frontpage
\usepackage{wallpaper}
\usepackage{fancyhdr}
\usepackage{lastpage} % Included so that \LastPage can be used to get pagenumber for last page
\usepackage{titlesec} % Include to control chapter and section display
\usepackage{tcolorbox} % Included to be able to make colored, rounded textboxes


%% My commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\todo[1]{\textcolor{red}{\textbf{#1}}}

\titleformat{\chapter}[block]
  {\Huge\bfseries}{\thechapter.}{0.5em}{\Huge}
\titlespacing*{\chapter}{0pt}{-15pt}{10pt}

Sorry for the big code-snippet, but I am clueless as to where it goes wrong.

  • 2
    Well, you say \begin{figure}[ht], which means "here or on top". Try changing it to [htp], which adds the option to place the figure on a floats-only page. – yo' Feb 12 '18 at 12:23
  • Thanks for the suggestion, but just tried it out, and it doesn't work. – Anders Olsen Feb 12 '18 at 13:10
  • 1
    As a last resort you can always position the figure(s) manually: tex.stackexchange.com/questions/375068 – Dr. Manuel Kuehner Feb 12 '18 at 19:24
  • Eurika! The package "float" combined with [H] as a placement option does exactly what I want! Thanks a lot. :) – Anders Olsen Feb 13 '18 at 13:05
1

The default, and often the best, location for floats is [tbp] (top, bottom, page). There are macros you can use to change how a float may be located on a page. These, together with the default value in parentheses, are

Change these with \setcounter:

topnumber (2) max number of floats at top of page

bottomnumber (1) max number of floats at bottom of page

totalnumber (3) max number of floats on a text page

dbltopnumber (2) like topnumber for double column floats

Change the following with \renewcommand:

\topfraction (0.7) max fraction of page reserved for top floats

\bottomfraction (0.3) max fraction of page for bottom floats

\textfraction (0.2) min fraction of page that must have text

\dbltopfraction (0.7) like \topfraction for double column floats

\floatpagefraction (0.5) min fraction of a float page that must have float(s)

\dblfloatpagefraction (0.5) like \floatpagefraction for double column floats

There are also macros for controlling the spacing around floats.

The memoir class documentation (< texdoc memoir) gives more details in its section 10.4 Where LaTeX puts floats.

Adjust the above parameters until you get the layout that suits you.

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.