如下面的屏幕截图所示,表格和后面的文本之间没有间距。这是什么原因造成的?最好的解决方案是什么?
这是我的乳胶:
\documentclass{report}
% \usepackage[dvips]{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}
\begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|}
\hline
\multicolumn{1}{|c||}{} & \multicolumn{3}{c|}{\textbf{Performance}} \\
\multicolumn{1}{|c||}{\textbf{Method}} & \multicolumn{1}{c}{Excellent} & \multicolumn{1}{c}{Suboptimal} & \multicolumn{1}{c|}{Poor} \\
\cline{2-4}
Title Search & 22 & 15 & 14 \\
Newline Freq. & 44 & 3 & 4 \\
\hline
\end{tabular}
As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.
\end{document}
- - - - - - - - - - - - - - 编辑 - - - - - - - - - - - - - - -
当我尝试在我的完整 Latex 文档中使用 Karlo 发布的解决方案时,我的表格出现在枚举列表中的两个项目之间。以下是屏幕截图:
使用以下代码,我能够得到与上面的屏幕截图类似(并且最有可能相关)的问题:
\documentclass{report}
% \usepackage[dvips]{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}
\begin{enumerate}
\item \textbf{Excellent}: The trimming occurred exactly where desired.
\item \textbf{Suboptimal}: The trimming occurred within a couple sentences of where desired.
\item \textbf{Poor}: A good chunk (more than a 3-4 sentences) of the book was erroneously trimmed or a significant amount of the noise was kept.
\end{enumerate}
\begin{table}
\begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|}
\hline
\multicolumn{1}{|c||}{} & \multicolumn{3}{c|}{\textbf{Performance}} \\
\multicolumn{1}{|c||}{\textbf{Method}} & \multicolumn{1}{c}{Excellent} & \multicolumn{1}{c}{Suboptimal} & \multicolumn{1}{c|}{Poor} \\
\cline{2-4}
Title Search & 22 & 15 & 14 \\
Newline Freq. & 44 & 3 & 4 \\
\hline
\end{tabular}
\end{table}
As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.
\end{document}
使用上述代码,尽管表格位于代码中的枚举列表之后,但它会在列表之前完全输出。
答案1
这是因为您已将表格排版在常规文本旁边。通常,表格会放在浮动环境中,就像您对数字所做的那样(例如,请参阅这里)。
像这样调整您的代码:
\documentclass{report}
% \usepackage[dvips]{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}
\begin{table}
\caption{Caption text}
\label{myTable}
\center
\begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|}
\hline
\multicolumn{1}{|c||}{} & \multicolumn{3}{c|}{\textbf{Performance}} \\
\multicolumn{1}{|c||}{\textbf{Method}} & \multicolumn{1}{c}{Excellent} & \multicolumn{1}{c}{Suboptimal} & \multicolumn{1}{c|}{Poor} \\
\cline{2-4}
Title Search & 22 & 15 & 14 \\
Newline Freq. & 44 & 3 & 4 \\
\hline
\end{tabular}
\end{table}
As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset (Table \ref{myTable}).
\end{document}
给出:
更新
与图形一样,LaTeX 决定将浮动放置在何处。使用\begin{table}[h!]
强制浮动位置(参见替代字母列表这里)。
答案2
\documentclass{report}
% \usepackage[dvips]{graphicx}
\usepackage{multirow}
\usepackage{tabularx, booktabs}%<-----------------new
\begin{document}
\begin{enumerate}
\item \textbf{Excellent}: The trimming occurred exactly where desired.
\item \textbf{Suboptimal}: The trimming occurred within a couple sentences of where desired.
\item \textbf{Poor}: A good chunk (more than a 3-4 sentences) of the book was erroneously trimmed or a significant amount of the noise was kept.
\end{enumerate}
\begin{table}[h]%<-------------------------added
\begin{tabular}{ p{3cm}p{2cm}p{2cm}p{2cm}}
\toprule
\multicolumn{1}{c}{}
& \multicolumn{3}{c}{\textbf{Performance}} \\
\multicolumn{1}{c}{\textbf{Method}}
& \multicolumn{1}{c}{Excellent}
& \multicolumn{1}{c}{Suboptimal}
& \multicolumn{1}{c}{Poor} \\
\cmidrule{2-4}
Title Search
& 22
& 15
& 14 \\
Newline Freq.
& 44
& 3
& 4 \\
\bottomrule
\end{tabular}
\end{table}
As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.
\end{document}
答案3
使用提供的 MWE 无法重现您的问题。表格与后面文本的垂直距离由默认值定义\textfloatsep
(有关详细信息,请参阅例如沃纳的回答)。
因此,现在看来您的问题不是问题标题中所述的问题,而是浮动表的放置问题。请相应地更正问题标题。
关于浮动放置的可能性,请参阅 wikiLaTeX/浮点数、图形和标题。根据此描述,您应该为浮动添加放置选项table
,例如\begin{table}[htb]
将表格放置在您想要的位置(如果有足够的空间,否则它将移动到下一页的顶部)。
无关:
我将使用该tabularray
包编写您的表格。使用它,您可以获得更专业的外观:
\documentclass[11pt,a4paper,twoside,openright]{report}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\usepackage[skip=1ex]{caption}
\usepackage{lipsum}
\begin{document}
\lipsum[65]
\begin{table}[htb]
\centering
\caption{My table}
\label{tab:tblr}
\begin{tblr}{width=0.8\linewidth,
colspec={ X[2,l] *{3}{X[si={table-format=2.0}, c]} },
row{1} ={font=\bfseries}
}
\toprule
\SetCell[r=2]{c,f} Method
& \SetCell[c=3]{c} {{{Performance}}}
& & \\
\midrule
& \SetCell[c=1]{c} {{{Excellent}}}
& {{{Suboptimal}}}
& {{{Poor}}} \\
\midrule
Title Search & 22 & 15 & 14 \\
Newline Frequency & 44 & 3 & 4 \\
\bottomrule
\end{tblr}
\end{table}
\lipsum[66]
\end{document}
答案4
一些建议:
由于您不希望表格“浮动”——在 LaTeX 特定意义上——并且由于您似乎不想提供
\caption
,因此使用环境实际上毫无意义table
。相反,只需将tabular
材料放在center
列表末尾的环境中即可。使用center
环境还有一个额外的好处,即不会导致最终列表项和表格材料之间出现夸张的垂直分离。我会从一个
enumerate
环境切换到另一个description
环境,尤其是当它看起来没有任何意义时编号这几项。booktabs
我还会通过加载包、摆脱所有垂直规则并\hline
根据需要用 --\toprule
、\midrule
和\bottomrule
替换,让表格看起来更开放。而且,我只会使用和列类型来让列占据其自然宽度,更重要的是,因为单元格内似乎不需要换\cline{2-4}
行。而且,由于表格不是那么大,我认为没有必要\cmidrule(l){2-4}
l
c
大胆的标题单元格,使其在视觉上脱颖而出。
\documentclass{report}
\usepackage{tabularx,booktabs}
\begin{document}
\begin{description}
\item[Excellent] The trimming occurred exactly where desired.
\item[Suboptimal] The trimming occurred within a couple sentences of where desired.
\item[Poor] A good chunk (more than 3 to 4 sentences) of the book was erroneously trimmed or a significant amount of the noise was kept.
\end{description}
\begin{center}
\begin{tabular}{@{} l *{3}{c} @{}}
\toprule
Method & \multicolumn{3}{c}{Performance} \\
\cmidrule(l){2-4}
& Excellent & Suboptimal & Poor \\
\midrule
Title Search & 22 & 15 & 14 \\
Newline Freq. & 44 & 3 & 4 \\
\bottomrule
\end{tabular}
\end{center}
As the change point detection algorithm performs quite well on these 50 samples and is much better than the title search method, we use it to trim our entire dataset.
\end{document}