多个浮动元素本应放在一页上,却分散在两页上

多个浮动元素本应放在一页上,却分散在两页上

我在 LaTeX 中遇到了一个奇怪的布局问题,由于某种原因,浮动元素可以清楚地适合一页,分布在两页上,即使使用较大的 vspace。

布局问题

附图是以下代码的编译结果:

\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}

我在使用此模板时曾多次遇到此问题。奇怪的是,如果我设法将尺寸缩小到足以将浮动元素集中在一页上,我仍然可以在同一页上添加一些文本,而不会弄乱布局。即使尺寸缩小与页面不适合的内容相差 1%。

这是我的序言。

\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}

抱歉,代码片段太大了,但我不知道它哪里出了问题。

答案1

浮动元素的默认位置(通常也是最佳位置)是[tbp](顶部、底部、页面)。您可以使用宏来更改浮动元素在页面上的位置。这些宏与括号中的默认值一起,是

将其更改为\setcounter

topnumber(2)页面顶部的最大浮动数量

bottomnumber(1)页面底部的最大浮动数量

totalnumber(3)文本页面上的最大浮动数量

dbltopnumber(2)类似于topnumber双列浮点数

更改以下内容\renewcommand

\topfraction(0.7)页面中为顶部浮动保留的最大比例

\bottomfraction(0.3)页面底部浮动的最大分数

\textfraction(0.2)页面中必须包含文本的最小部分

\dbltopfraction(0.7)类似于\topfraction双列浮点数

\floatpagefraction(0.5)浮动页面的最小分数,必须有浮动

\dblfloatpagefraction(0.5)类似于\floatpagefraction双列浮点数

还有一些用于控制浮点数周围间距的宏。

课程memoir文档(< texdoc memoir)在其部分中提供了更多详细信息10.4 LaTeX 放置浮点数的位置

调整上述参数,直到获得适合您的布局。

相关内容