![当内容超过三个时,内容会显示在部分之外](https://linux22.com/image/302049/%E5%BD%93%E5%86%85%E5%AE%B9%E8%B6%85%E8%BF%87%E4%B8%89%E4%B8%AA%E6%97%B6%EF%BC%8C%E5%86%85%E5%AE%B9%E4%BC%9A%E6%98%BE%E7%A4%BA%E5%9C%A8%E9%83%A8%E5%88%86%E4%B9%8B%E5%A4%96.png)
我有以下 LATEX 文档:
\documentclass[a4paper,12pt]{article}
\begin{document}
\section{Enemies}
\begin{table}[ht]
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Grey&Beard&1234567890&the ocean&Enemies\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Friends}
\begin{table}[ht]
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
John&Doe&1234567890&1424 Brooklyn Ave.&Friends\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Relatives}
\begin{table}[ht]
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
My&Self&1234567890&My current location&Relatives\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Mythical Beasts}
\begin{table}[ht]
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Puff&Dragon&1234567890&cave by the ocean&Mythical Beasts\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Public Figures}
\begin{table}[ht]
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Santa&Claus&10234987&North Pole&Public Figures\\
\hline %inserts single line
\end{tabular}
\end{table}
\end{document}
编译后的样子如下:
如您所见,前几个部分呈现正确,但前三个部分之后,其他部分的内容出现在部分之外。我尝试重新排序这些部分,但发生了同样的事情。
问题是什么?
编辑:
新示例:
\documentclass[a4paper,12pt]{article}
\title{Contact List}
\date{\today}
\begin{document}
\maketitle
\section{Enemies}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Friends}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
John&Doe&1234567890&1424 Brooklyn Ave.&Friends\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Relatives}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
My&Self&1234567890&My current location&Relatives\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Mythical Beasts}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Puff&Dragon&1234567890&cave by the ocean&Mythical Beasts\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Public Figures}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Santa&Claus&10234987&North Pole&Public Figures\\
\hline %inserts single line
\end{tabular}
\end{table}
\end{document}
答案1
这table
环境是浮点环境。LaTeX 将浮点的内容放在它认为最合适的位置,这可能不直接对应于您在代码中放置浮点的位置。请参阅浮动桌子。
除非您确实需要表格的浮动功能(但从您的问题来看,您似乎不需要),否则您只需从每个表格中删除\begin{table}
和行即可。环境不需要包装在环境中。\end{table}
tabular
table
\section{Enemies}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Grey&Beard&1234567890&the ocean&Enemies\\
\hline %inserts single line
\end{tabular}
\section{Friends}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
John&Doe&1234567890&1424 Brooklyn Ave.&Friends\\
\hline %inserts single line
\end{tabular}
\section{Relatives}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
My&Self&1234567890&My current location&Relatives\\
\hline %inserts single line
\end{tabular}
\section{Mythical Beasts}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Puff&Dragon&1234567890&cave by the ocean&Mythical Beasts\\
\hline %inserts single line
\end{tabular}
\section{Public Figures}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Santa&Claus&10234987&North Pole&Public Figures\\
\hline %inserts single line
\end{tabular}
\end{document}
如果您确实决定需要table
(例如,对于标题),您可以添加!
到选项声明中,强制浮动出现在您指定的位置:
\documentclass[a4paper,12pt]{article}
\begin{document}
\section{Enemies}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Grey&Beard&1234567890&the ocean&Enemies\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Friends}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
John&Doe&1234567890&1424 Brooklyn Ave.&Friends\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Relatives}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
My&Self&1234567890&My current location&Relatives\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Mythical Beasts}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Puff&Dragon&1234567890&cave by the ocean&Mythical Beasts\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Public Figures}
\begin{table}[!h] % note the !
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Santa&Claus&10234987&North Pole&Public Figures\\
\hline %inserts single line
\end{tabular}
\end{table}
\end{document}
编辑
为了获得更强的效果,请使用表格上的float
包和选项。[H]
\documentclass[a4paper,12pt]{article}
\usepackage{float}
\title{Contact List}
\date{\today}
\begin{document}
\maketitle
\section{Enemies}
\begin{table}[H] % note the H
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Friends}
\begin{table}[H] % note the H
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
John&Doe&1234567890&1424 Brooklyn Ave.&Friends\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Relatives}
\begin{table}[H] % note the H
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
My&Self&1234567890&My current location&Relatives\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Mythical Beasts}
\begin{table}[H] % note the H
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Puff&Dragon&1234567890&cave by the ocean&Mythical Beasts\\
\hline %inserts single line
\end{tabular}
\end{table}
\section{Public Figures}
\begin{table}[H] % note the H
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Santa&Claus&10234987&North Pole&Public Figures\\
\hline %inserts single line
\end{tabular}
\end{table}
\end{document}
答案2
在 LaTeX 中放置浮动并不总是那么容易,因为浮动可能不会到达你想要的位置。这两个常见问题解答中详细讨论了这个问题如何影响 LaTeX 中图形和表格等浮动环境的位置?和将表格/图片放在靠近提及的地方。
从表面上看,你似乎对文档中浮动的内容不感兴趣。相反,你只是想要表示tabular
一些应该包含在部分中的数据。为此,你不需要环境table
。事实上,atabular
可以独立存在,而无需放置在table
浮动中。所以,不要使用它。
其次,您当前限制“三个表格”的原因源于 LaTeX 的浮动设置。事实上,任何页面上可以拥有的浮动总数通过计数器设置为默认值 3。totalnumber
增加这个数字可能会有所帮助,但这不一定是最好的主意,因为其他计数器会跟踪浮动在页面顶部/底部占用了多少空间。这反过来可能会导致浮动的移动超出您的控制范围。
考虑到以上情况,我建议使用tabular
-only 实现。如果您想要字幕,您可以像添加其他内容一样将其添加到文本中。如果您想要编号标题(如常规的table
),您可以包括capt-of
包裹。最后,对于需要跨页边界的表格,您可以考虑使用longtable
。
这是一个展示可能设置的最小示例:
\documentclass{article}
\usepackage{capt-of}
\title{Contact List}
\date{\today}
\begin{document}
\maketitle
\section{Enemies}
\begin{center}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
Grey&Beard&1234567890&the ocean&Enemies\\
\hline %inserts single line
\end{tabular}
\end{center}
\section{Friends}
\begin{center}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
John&Doe&1234567890&1424 Brooklyn Ave.&Friends\\
\hline %inserts single line
\end{tabular}
\vspace{\abovecaptionskip}%
This is a caption for the table.
\end{center}
\section{Relatives}
\begin{center}
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
My&Self&1234567890&My current location&Relatives\\
\hline %inserts single line
\end{tabular}
\captionof{table}{This is a caption for the table.}% Placed inside a (center) group
\end{center}
\section{Mythical Beasts}
\noindent
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Puff&Dragon&1234567890&cave by the ocean&Mythical Beasts\\
\hline %inserts single line
\end{tabular}
\section{Public Figures}
\noindent
\begin{tabular}{c c c c c} % centered columns (4 columns)
First Name & Last Name & Phone & Address & Category \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
Santa&Claus&10234987&North Pole&Public Figures\\
\hline %inserts single line
\end{tabular}
\end{document}