表格被页面裁切且不居中

表格被页面裁切且不居中

我正在编写一个应该居中的表格,但它却没有,而且它不是放在页面中,而是被页面剪切。

代码如下:

\begin{table}[h]
    \centering
    \begin{tabular}{|l|c|c|c|c|c|c|c|c|}
    \hline
    \textbf{benchmark} & \textbf{\#input} & \textbf{\#output} & \textbf{SOP} & \textbf{BCLP-1} & \textbf{BCLP-2} & \textbf{BCLP-3} & \textbf{BCLP-4} & \textbf{BCLP-5}\\
    \hline
    accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
    alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\

最终结果如下: 在此处输入图片描述

我怎样才能使表格适合页面并且出现在中心?

编辑:文档类是\documentclass[12pt]{article}

编辑2:如果没有简单的解决方案,我至少可以将桌子旋转 90° 并使其水平放置吗?

答案1

如果需要,可以将表格挤进标准边距内。我已减少tabcolsep并删除了垂直规则。由于表格因标题而太宽,我将标题的公共部分添加到一行中,并减小了字体大小。我以为这不会改变含义,但如果我错了,这不是要走的路。如果可能的话,您也可以将#inputand缩写#output#inand#out

最后五列,我使用固定宽度排版,大批w-列。

我做了三个示例,一个带有垂直规则,一个没有,一个带有表格中的标题,不同之处在于我删除了粗体并减小了字体大小以减小标题的大小:

示例 1:booktabs 版本

此外,我还做了一些常规的事情来使表格更易读:书页规则,按小的空白对行进行分组,删除左右边距 ( @{})。

如果你的表格有标题,我建议使用三部分表,如果标题是多行的,则自动确保表格和标题相同。标题将帮助您格式化标题。只有数字的列应右对齐(第 2 列至第 6 列):

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{array, booktabs, caption, threeparttable}
\setlength{\tabcolsep}{0.5em}
\begin{document}

\begin{table}
\centering
\begin{threeparttable}
\caption{A table is much nicer if you use booktabs and remove vertical rules. threepartable ensure that caption and table is of the same length}
\begin{tabular}{@{}lrrr*{2}{wr{\dimexpr(1.15cm-(2\tabcolsep))}}*{3}{wc{\dimexpr(1.15cm-(2\tabcolsep))}}}
\toprule
&&&&\multicolumn{5}{>{\centering\arraybackslash}p{5.71cm}}{\small\bfseries BCLP}\\ \cmidrule(l{\tabcolsep}){5-9}
\small\textbf{Benchmark} & \small\textbf{\#input} & \small\textbf{\#output} & \small\textbf{SOP} & \multicolumn{1}{c}{\small\bfseries 1} & \multicolumn{1}{c}{\small\bfseries 2} & \multicolumn{1}{c}{\small\bfseries 3} & \multicolumn{1}{c}{\small\bfseries 4} & \multicolumn{1}{c}{\small\bfseries 5}\\
\midrule
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\\addlinespace
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\\addlinespace
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
\bottomrule    
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

示例 2:垂直线

在这个例子中,我必须将 进一步减小tabcolsep0.411em,因为垂直规则需要侧边距。我还将行高增加了 2 pt,以避免水平规则和单元格内容发生冲突。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{array}
\begin{document}

\begin{table}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{0.413em}
\centering
\begin{tabular}{|l|*{5}{r|}*{3}{c|}}
\hline
&&&&\multicolumn{5}{>{\centering\arraybackslash}p{5cm}|}{\small\bfseries BCLP}\\ \cline{5-9}
\small\textbf{Benchmark} & \small\textbf{\#input} & \small\textbf{\#output} & \small\textbf{SOP} & \multicolumn{1}{c|}{\small\bfseries 1} & \multicolumn{1}{c|}{\small\bfseries 2} & \multicolumn{1}{c|}{\small\bfseries 3} & \multicolumn{1}{c|}{\small\bfseries 4} & \multicolumn{1}{c|}{\small\bfseries 5}\\
\hline
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\[1ex]
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\[1ex]
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
\hline
\end{tabular}
\end{table}
\end{document}

示例 3:带有原始表格标题

tabolsep进一步减少。页眉处的字体较小。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{array}
\begin{document}

\begin{table}
\setlength{\extrarowheight}{2pt}
\setlength{\tabcolsep}{0.3em}
\centering
\rule{\linewidth}{2pt}
\bigskip
\begin{tabular}{|l|*{5}{r|}*{3}{c|}}
\hline
\footnotesize  Benchmark & \footnotesize \#input & \footnotesize \#output & \footnotesize SOP & \multicolumn{1}{c|}{\footnotesize BCLP-1} & \multicolumn{1}{c|}{\footnotesize BCLP-2} & \multicolumn{1}{c|}{\footnotesize BCLP-3} & \multicolumn{1}{c|}{\footnotesize BCLP-4} & \multicolumn{1}{c|}{\footnotesize BCLP-5}\\
\hline
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\[1ex]
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\[1ex]
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
alu4.pla & 14 & 8 & 575 & 923  & 921 & XXX & YYY & ZZZ\\
accpla.pla & 50 & 69 & 175 &  1457  & 1458 & XXX & YYY & ZZZ\\
\hline
\end{tabular}
\end{table}
\end{document}

答案2

我通过旋转桌子解决了这个问题。为了做到这一点,我更换了

\begin{table}...\end{table}

\begin{sidewaystable}...\end{sidewaystable} 

从包中rotating

如果有人能告诉我如何在不旋转的情况下缩小以适应桌子,请在这里说出来。这仍然是我喜欢的解决方案。

相关内容