如何正确地使表格适合页边距?

如何正确地使表格适合页边距?

我有一张表,定义如下:

\documentclass[a4paper]{paper}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}

\begin{table}[h]
\centering
\resizebox{\textwidth}{!}{
\begin{tabular}{|*{10}{c|}}
\hline
 \multirowcell{3}{Work} & \multirowcell{3}{Prime\\[1ex] (bits)} & \multicolumn{5}{c|}{Area} & \multicolumn{3}{c|}{Time} \\
 \cline{3-10}
& & \makecell{\# \\FFs} & \makecell{\#\\ LUTs} & \makecell{\#\\ Slices} & \makecell{\# \\ DSPs} & \makecell{\# \\ BRAMs} & \makecell{Freq.\\ (MHz)} & \makecell{Latency \\ (cc${}\times 10^6$)} & \makecell{Total time\\ (ms)} \\
\hline \hline
% Partially removed for brevity
\end{tabular}}
\caption{Comparison of hardware architectures}
\label{tab:hard}
\end{table}

\end{document}

重点是,这种方法可以很好地将表格调整到页面边缘,但这里有几个人指出,\resizebox不建议使用这种方法,因为这可能会导致字体大小不一致。因此,我想听听(并看看一些示例)让表格调整到页面边缘的正确方法是什么?还请注意,我也需要在表格中使用一些脚注。

答案1

删除标题单元格中的一些重复内容并切换到环境tabular*\tabcolsep设置为 0pt)使您能够以纵向模式排版材料,而无需诉诸\resizebox“锤子”。并且,为了获得间距更好的水平线,请加载booktabs包并使用\toprule\midrule\cmidrulebottomrule代替\hline\cline。最后,如果您对创建具有开放或吸引人的“外观”的表格感兴趣,请删除所有垂直条 - 它们不是必需的。真的。

在此处输入图片描述

\documentclass[a4paper]{paper}
\usepackage{multirow,booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}[h]
\setlength\tabcolsep{0pt} % make LaTeX figure out optim. amount of intercol. space
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} *{10}{c} }
\toprule
 \multirowcell{3}{Work} & 
 \multirowcell{3}{Prime\\[1ex] (bits)} & 
 \multicolumn{5}{c}{Area} & 
 \multicolumn{3}{c}{Time} \\
\cmidrule{3-7} \cmidrule{8-10}
& & \makecell{\# \\FFs} & \makecell{\#\\ LUTs} & \makecell{\#\\ Slices} 
& \makecell{\# \\ DSPs} & \makecell{\# \\ BRAMs} & \makecell{Freq.\\ (MHz)} 
& \makecell{Latency \\ (cc${\times}10^6$)} & \makecell{Total\\ (ms)} \\
\midrule 
\bottomrule
% Partially removed for brevity
\end{tabular*}
\caption{Comparison of hardware architectures}
\label{tab:hard}
\end{table}

\end{document}

答案2

如果不看表格数据就很难说,但是这适合文本宽度:

在此处输入图片描述

\documentclass[a4paper]{paper}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}

\begin{table}[htp]% never h on it own
\centering
\small\setlength\tabcolsep{4.5pt}
\begin{tabular}{@{}|*{10}{c|}@{}}
\hline
 \multirowcell{3}{Work} & \multirowcell{3}{Prime\\[1ex] (bits)} & \multicolumn{5}{c|}{Area} & \multicolumn{3}{c|}{Time} \\
 \cline{3-10}
& & \makecell{\# \\FFs} & \makecell{\#\\ LUTs} & \makecell{\#\\ Slices} & \makecell{\# \\ DSPs} & \makecell{\# \\ BRAMs} & \makecell{Freq.\\ (MHz)} & \makecell{Latency \\ (cc${}\times 10^6$)} & \makecell{Total\\ (ms)} \\
\hline \hline
% Partially removed for brevity
\end{tabular}
\caption{Comparison of hardware architectures}
\label{tab:hard}
\end{table}

\end{document}

答案3

在此处输入图片描述下面是使用 tabularx 的示例

\documentclass[a4paper, 12pt, twopage, openright]{memoir}
    \usepackage[lmargin=2.5cm, rmargin=2.5cm, tmargin=2.5cm, bmargin=2.5cm]{geometry}
    \usepackage{amsmath, amssymb}
    \usepackage{graphicx,color}
    \usepackage{multirow}
    \usepackage{subcaption}
    \usepackage{float}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage{tabularx}
    \usepackage{caption}
    \usepackage{enumitem} 
    \usepackage[font={color=black},figurename=Figure., tablename=Table.]{caption}
    \newcolumntype{Y}{>{\centering\arraybackslash}X}
    \captionsetup{justification=centering, textfont=small}
    \begin{document}
    \begin{table}[H]
    \setlength{\tabcolsep}{4pt}
    \centering\small
    \centering
    \caption{Comparison of experimental and predicted fracture energies of CSR particles modified epoxies}
    \label{tab2}
    \begin{tabular}{@{}ccccccc@{}}
    \hline
    Small CSR       & $\mathrm{\Delta G_s}$  & $\mathrm{\Delta G_v}$         & $\mathrm{\Delta G_v}$    & Predicted   & Predicted    & Experimental \\ 
    (wt\%)  & $\mathrm{J/m^2}$ & $\mathrm{J/m^2}$       & $\mathrm{J/m^2}$          & $\mathrm{G_{IC}}$ $\mathrm{(J/m^2)}$  & $\mathrm{G_{IC}}$ $\mathrm{(J/m^2)}$   & $\mathrm{G_{IC}}$ $\mathrm{(J/m^2)}$ \\ 
            &      &  $\mathrm{r_v}$ measured & $\mathrm{r_v= (1+\gamma_f)r_p}$ &  $\mathrm{r_v}$ measured & $\mathrm{r_v= (1+\gamma_f)r_p}$ &              \\ \midrule
    0           & 0    & 0           & 0             & 78          & 78           & 78 $\pm$ 4       \\ 
    3        & 49   & 123         & 131           & 250         & 258          & 220 $\pm$ 10      \\ 
    6        & 69   & 242         & 258           & 389         & 405          & 430 $\pm$ 12      \\ 
    9         & 81  & 349        & 373          & 508        & 531          & 530 $\pm$ 32      \\ \hline
    Large CSR       & $\mathrm{\Delta G_s}$  & $\mathrm{\Delta G_v}$         & $\mathrm{\Delta G_v}$           & Predicted   & Predicted    & Experimental \\ 
    (wt\%)  & $\mathrm{J/m^2}$ & $\mathrm{J/m^2}$       & $\mathrm{J/m^2}$          & $\mathrm{G_{IC}}$ $\mathrm{(J/m^2)}$  & $\mathrm{G_{IC}}$ $\mathrm{(J/m^2)}$   & $\mathrm{G_{IC}}$ $\mathrm{(J/m^2)}$ \\ 
                  &      &  $\mathrm{r_v}$ measured & $\mathrm{r_v= (1+\gamma_f)r_p}$ & $\mathrm{r_v}$  measured & $\mathrm{r_v= (1+\gamma_f)r_p}$ &              \\ \hline
    0           & 0    & 0           & 0             & 78          & 78           & 78 $\pm$ 4       \\ 
    3       & 49   & 108        & 135           & 235         & 262          & 121 $\pm$ 11      \\ 
    6        & 66   & 196        & 246           & 340         & 389          & 270 $\pm$ 12      \\ 
    9        & 78  & 287      & 360          & 443         & 516         & 403 $\pm$ 32      \\ \hline
    \end{tabular}
    \end{table}
    \end{document}

相关内容