缩放表格以适合整个页面

缩放表格以适合整个页面

我使用 Excel2Latex 从我的 excel 文件中抽取了一些表格。一切正常,但输出图片如下:

表格图片

我希望表格能够覆盖整个页面。这可行吗?如果可以,我该怎么做?这是我使用的代码:

\documentclass{article}
\usepackage{bigstrut}

\begin{document}

  % Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering
\caption{Table shows the commulative oxygen levels at 2 minute time intervals. The displacement is measured in \textbf{cm}}
\begin{tabular}{|r|r|r|r|r|r|r|r|r|r|}
\cline{2-10}    
\multicolumn{1}{r|}{} & \multicolumn{9}{c|}{\textbf{Time of reading (in min)}}   \\
\cline{2-10}    
\multicolumn{1}{r|}{} & \multicolumn{1}{r}{\textbf{0}} & \multicolumn{1}{r}{\textbf{2}} & \multicolumn{1}{r}{\textbf{4}} & \multicolumn{1}{r}{\textbf{6}} & \multicolumn{1}{r}{\textbf{8}} & \multicolumn{1}{r}{\textbf{10}} & \multicolumn{1}{r}{\textbf{12}} & \multicolumn{1}{r}{\textbf{14}} & \textbf{16} \bigstrut\\
    \hline
    \hline
    \textbf{Treatment 1} & 0     & 0     & 0.5   & 0.7   & 0.9   & 0.9   & 1     & 1.2   & 1.8 \bigstrut\\
    \hline
    \textbf{Treatment 2} & 0     & 0     & 0     & 0.1   & 0.1   & 0.1   & 0.1   & 0.2   & 0.5 \bigstrut\\
    \hline
    \textbf{Treatment 3} & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0 \bigstrut\\
    \hline
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%
\end{document}

答案1

要为表格声明一些预定义的宽度,您可以使用环境tabular*,或者更好的是,使用tabularx来自表格型包。我还建议您考虑对表格布局进行一些更改:1)不要使用垂直规则。2)使用书签包。这是经过一些修改的表:

\documentclass{book}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\begin{table}
  \centering
  \caption{Table shows the commulative oxygen levels at 2 minute time 
       intervals. The displacement is measured in \textbf{cm}}
  \begin{tabularx}{\textwidth}{@{}>{\bfseries}c*{9}{X}@{}}
  \toprule
  Treatment & \multicolumn{9}{c@{}}{\textbf{Time of reading (in min)}} \\
  \cmidrule(l){2-10}    
  & \textbf{0} & \textbf{2} & \textbf{4} & \textbf{6} & \textbf{8} 
  & \textbf{10} & \textbf{12} & \textbf{14} & \textbf{16} \\
  \cmidrule(r){1-1}\cmidrule(l){2-10}
  1 & 0     & 0     & 0.5   & 0.7   & 0.9   & 0.9   & 1     & 1.2   & 1.8 \\
  2 & 0     & 0     & 0     & 0.1   & 0.1   & 0.1   & 0.1   & 0.2   & 0.5 \\
  3 & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0 \\
  \bottomrule
  \end{tabularx}%
  \label{tab:addlabel}%
\end{table}%

\end{document}

在此处输入图片描述

答案2

tabularx包提供了tabularx为此目的而构建的环境。第一个参数是表格的宽度。

这是您在 MWE 中的表格

截屏

\documentclass{report}

\usepackage{bigstrut}
\usepackage{tabularx}

\begin{document}

\begin{table}[htbp]
  \centering
  \caption{Table shows the commulative oxygen levels at 2 minute time intervals. The displacement is measured in \textbf{cm}}
  \begin{tabularx}{\textwidth}{|r|X|X|X|X|X|X|X|X|X|}
\cline{2-10}    
\multicolumn{1}{r|}{} & \multicolumn{9}{c|}{\textbf{Time of reading (in min)}}   \\
\cline{2-10}
\multicolumn{1}{r|}{} & \multicolumn{1}{r}{\textbf{0}} & 
\multicolumn{1}{r}{\textbf{2}} & \multicolumn{1}{r}{\textbf{4}} & 
\multicolumn{1}{r}{\textbf{6}} & \multicolumn{1}{r}{\textbf{8}} & 
\multicolumn{1}{r}{\textbf{10}} & \multicolumn{1}{r}{\textbf{12}} & 
\multicolumn{1}{r}{\textbf{14}} & \textbf{16} \bigstrut\\
    \hline
    \hline
    \textbf{Treatment 1} & 0     & 0     & 0.5   & 0.7   & 0.9   & 0.9   & 1     & 1.2   & 1.8 \bigstrut\\
    \hline
    \textbf{Treatment 2} & 0     & 0     & 0     & 0.1   & 0.1   & 0.1   & 0.1   & 0.2   & 0.5 \bigstrut\\
    \hline
    \textbf{Treatment 3} & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0 \bigstrut\\
    \hline
    \end{tabularx}%
  \label{tab:addlabel}%
\end{table}%

\end{document}

答案3

您可以使用tabular*环境而不是环境tabulartabular*环境需要一个额外的参数,您应该将其设置为\textwidth。在环境的第二个参数中,使用构造@\extracolsep{\fill}}来指示所有列间空间都应该增加\fill,这将使整个环境占据宽度\textwidth

在以下 MWE 中,我擅自简化了您的代码。例如,我已将第一列的内容定义为自动以粗体排版,从而节省了以后的一些编码。顺便说一句,表格第二行中的许多命令都不是必需的。我还放弃了垂直规则,因为我认为它们不会显著增加表格的可理解性。最后,我使用了包中的\multicolumn命令\toprule、、和来获得一些间距良好的水平规则(代替使用)。\cmidrule\midrule\bottomrulebooktabs\hline

\documentclass{article}
\usepackage{array,booktabs}
\begin{document}
\begin{table}[h]
\caption{Table shows the commulative oxygen levels at 2 minute time intervals. 
The displacement is measured in \textbf{cm}}  \label{tab:addlabel}
\setlength\tabcolsep{0pt} % make LaTeX figure out optimal amount of intercol. whitespaced
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} >{\bfseries}l *{9}{l} }
\toprule
 & \multicolumn{9}{c}{\textbf{Time of reading (in min)}}   \\
\cmidrule{2-10}    
 & \textbf{0} & \textbf{2} & \textbf{4} & \textbf{6}  & \textbf{8} 
 & \textbf{10} & \textbf{12} & \textbf{14} & \textbf{16} \\
\midrule
Treatment 1 & 0{\phantom{.0}} & 0{\phantom{.0}} & 0.5 & 0.7 & 0.9 & 0.9 
   & 1 & 1.2 & 1.8 \\
Treatment 2 & 0   & 0  & 0   & 0.1 & 0.1 & 0.1 & 0.1 & 0.2 & 0.5 \\
Treatment 3 & 0   & 0  & 0   & 0   & 0   & 0   & 0   & 0   & 0   \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

在此处输入图片描述

答案4

我正在写一份报告,也遇到了类似的问题。我想在报告的附录中包含一个长表(跨越多页)。该表包含大约 100 列,但只有四行。我想在一页中包含最大列数。我正在使用以下 latex 命令行。如果能得到有利的考虑,我将不胜感激。

\begin{landscape}
\setlength\LTleft{2pt} \setlength\LTright{2pt}
\begin{table}[htbp] \caption*{}
\begin{longtable}{|l|p{4in}|l|p{4in}|}\hline
HS2&Description&HS2&Description \\ \hline
01&Live animals&20&Vegetable, fruit, nut, etc food preparations \\
\hline 02&Meat and edible meat offal&21&Miscellaneous edible
preparations \\ \hline 03&Fish, crustaceans, molluscs, aquatic
invertebrates nes&22&Beverages, spirits and vinegar \\ \hline
04&Dairy products, eggs, honey, edible animal product
nes&23&Residues, wastes of food industry, animal fodder \\ \hline
...
....
(up to 100 times)
\end{longtable}
\end{table}
\end{landscape}

相关内容