什么原因会导致 LaTeX 将文本和表格放在不同的页面上?

什么原因会导致 LaTeX 将文本和表格放在不同的页面上?

我的文档生成了很多页,其中一页是一段短文本,下一页是一段短表格,再下一页是另一段短文本,等等。大多数页面上都有足够的空间来容纳更多文本和表格,但不知何故,LaTeX 将它们视为油和水,并将它们完全分开。我该如何更改选项,使我的文档不包含 95% 的空白?以下是我的文件的基本样子。

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

\usepackage{tabularx} %For setting table widths
\usepackage{float}

\usepackage{graphicx} %%For loading graphic files

%% Math Packages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}

\usepackage[margin=1in]{geometry}

\begin{document}

\pagestyle{empty} %No headings for the first pages.
\title{Awesome Report}
\author{LaTex Noob}
\maketitle

\pagestyle{plain} %Now display headings: headings / fancy / ...

\section{Intro}\label{intro}
asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf 

\include{treeTrainAccuracy}

asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf 

\include{treeTestAccuracy}

asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf 

\include{svmTrainAccuracy}

asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf 

\include{svmTestAccuracy}

asdfa asdf asdfa asdf asdfa asdf asdfa asdf asdfa asdf 

所有内容均引用具有以下结构的表(当然值不同):

\begin{table}[ht]
\centering
\begin{tabularx}{\textwidth}{|l|X|X|l|X|X|X|}
  \hline
 & laying & sitting & standing & walk & walkdown & walkup \\ 
  \hline
laying & 221 &   0 &   0 &   0 &   0 &   0 \\ 
  sitting &   0 & 190 &   0 &   0 &   0 &   0 \\ 
  standing &   0 &   8 & 227 &   0 &   0 &   0 \\ 
  walk &   0 &   0 &   0 & 266 &   0 &   0 \\ 
  walkdown &   0 &   0 &   0 &   0 & 193 &   0 \\ 
  walkup &   0 &   0 &   0 &   0 &   0 & 210 \\ 
   \hline
\end{tabularx}
\caption{SVM training set accuracy. Rows represent actual values. Columns are predicted values.\label{tab:svmTrainAccuracy}} 
\end{table}

答案1

\include根据定义,在包含文件的开头和结尾处都会开始一个新页面。原因是,包含“包含”文件的文档应该只包含部分文件即可正确编译。即使文档仅部分编译,为了保留分页和编号,文件在\clearpage前后运行以确保所有浮动都被限制在包含的部分内(以及记录有关各种计数器和交叉引用的当前信息)。

理论上,更复杂的机制是可行的,但上述解决方案是 LaTeX 提供的。因此,\include基本上只适用于大型文档,每个此类文件都包含一整章或几章。

因此,解决您的问题的答案是使用\input

相关内容