表格显示空白处

表格显示空白处

我试图制作这张表,但里面有空白,我不知道为什么?有人能告诉我如何解决这个问题吗?

在此处输入图片描述

这是我的代码:

\documentclass{article}
\begin{document}
\renewcommand{\arraystretch}{1.3}
\small
\begin{table}[ht]
\begin{tabular}{|c|c|c|c|c|}
\hline
& \multicolumn{4}{|c|}{Display Format}& \\ \cline{2-5}
&\multicolumn{2}{|c|}{High information density}& \multicolumn{2}{|c|}{Low information density} &\\ \hline
Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ \hline
1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\ \hline
1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ \hline
\end{tabular}
\caption{Number of respondents per treatment}
\label{table:1}
\end{table}
\end{document}

答案1

第一行和第二行多了一个&。TeX 会抛出错误信息并新建一行作为错误恢复:

! Extra alignment tab has been changed to \cr.
<template> \endtemplate

l.9 & \multicolumn{4}{|c|}{Display Format}&
                                             \\ \cline{2-5}

修复了包括 Mico 的示例使固定

\documentclass{article}
\begin{document}
\renewcommand{\arraystretch}{1.3}
\small
\begin{table}[ht]
  \begin{tabular}{|c|c|c|c|c|}
    \hline
    & \multicolumn{4}{c|}{Display Format}\\ \cline{2-5}
    & \multicolumn{2}{c|}{High information density}& \multicolumn{2}{c|}{Low information density}\\ \hline
    Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ \hline
    1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\ \hline
    1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ \hline
  \end{tabular}
  \caption{Number of respondents per treatment}
  \label{table:1}
\end{table}
\end{document}

结果

顺便说一下,\small已设置外部环境table。因此它不会改变内部的字体大小,因为浮动环境通常会在开始时重置字体。

\documentclass{article}
\begin{document}
\begin{table}[ht]
  \small
  \begin{tabular}{|c|c|c|c|c|}
    \hline
    & \multicolumn{4}{c|}{Display Format} \\ \cline{2-5}
    & \multicolumn{2}{c|}{High information density}& \multicolumn{2}{c|}{Low information density}\\ \hline
    Cookie type & Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ \hline
    1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\ \hline
    1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ \hline
  \end{tabular}
  \caption{Number of respondents per treatment}
  \label{table:1}
\end{table}
\end{document}

结果为 \small

最后一个带有软件包的版本booktabs,更少更好的线条和间距:

\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[normal]{engord}% no option or option "raise" for raised suffixes

\begin{document}
\begin{table}[ht]
  \caption{Number of respondents per treatment}
  \label{table:1}
  \begin{tabular}{ccccc}
    \toprule
    & \multicolumn{4}{c}{Display Format}\\
    \cmidrule(lr){2-5}
    & \multicolumn{2}{c}{High information density} &
    \multicolumn{2}{c}{Low information density}\\
    \cmidrule(lr){2-3}
    \cmidrule(lr){4-5}
    Cookie type & Noticeable & Non-noticeable &
    Noticeable & Non-noticeable\\
    \midrule
    \engordnumber{1} & Group 1 & Group 2 & Group 3 & Group 4\\
    \engordnumber{1}/\engordnumber{3} &
    Group 5 & Group 6 & Group 7 & Group 8\\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

带有 booktabs 的结果

答案2

如果对四个数据列使用相同c的列类型,则这些列的宽度会明显不同。恕我直言,这会导致“外观”不太理想。因此,我建议您使用一种可以确保四个数据列宽度相同的列类型。包X提供的列类型就是这样一种列类型tabularx

我还想建议您(a)让表格看起来更“开放” - 主要是通过省略所有垂直线并使用包提供的宏\toprule\midrule\bottomrule而不是和- 以及(b)为三行标题提供更多的视觉结构,以帮助读者更轻松地获取信息。\cmidrulebooktabs\hline\cline

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered "X" columns
\begin{document}

\begin{table}
\setlength\tabcolsep{3pt} % default value: 6pt
\begin{tabularx}{\textwidth}{@{}lCCCC@{}}
\toprule
Cookie type & \multicolumn{4}{c@{}}{Display Format} \\ 
\cmidrule(l){2-5}
&\multicolumn{2}{c}{High information density}
&\multicolumn{2}{c@{}}{Low information density} \\ 
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& Noticeable& Non-noticeable& Noticeable& Non-noticeable\\ 
\midrule
1\textsuperscript{st} &Group 1&Group 2& Group 3&Group 4\\
1\textsuperscript{st}/3\textsuperscript{rd}&Group 5& Group 6&Group 7&Group 8\\ 
\bottomrule
\end{tabularx}
\caption{Number of respondents per treatment}
\label{table:1}
\end{table}

\end{document}

相关内容