使用 \adjustbox 缩小表​​格并处理 booktabs 边距

使用 \adjustbox 缩小表​​格并处理 booktabs 边距

我正在尝试缩小表格以适合页面(如上所述这里),但代码无法编译。另外,我的表格边距有一些微小的间隙,我该如何去除它们?

我的代码:

\adjustbox{max width=\textwidth}{
\begin{table}[!htbp]
    \centering
    \begin{tabular}{@{}|l|c|c|c|c|l|c|@{}}
        \toprule
        \multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{Sub-Item}}} & \multirow{2}{*}{\textbf{Projeto}} & \multirow{2}{*}{\textbf{Processos}} & \multicolumn{2}{c|}{\textbf{Valor individual por}} & \multirow{2}{*}{\textbf{Quantidade}} & \multirow{2}{*}{\textbf{Total}} \\ \cmidrule(lr){4-5}
        \multicolumn{1}{|c|}{} &  &  & \textbf{Projeto} & \textbf{Processo} &  &  \\ \midrule
        Serviço de medição & 1 & 4 &  &  & \multicolumn{1}{c|}{2} &  \\ \midrule
        Serviço de apoio a projeto & 1 & 4 &  &  & \multicolumn{1}{c|}{1} &  \\ \midrule
        \multicolumn{6}{|r|}{\textbf{Valor total}} & \multicolumn{1}{l|}{} \\ \bottomrule
    \end{tabular}
    \caption{Proposta de preço para item 1}
    \label{PropostaItem1}
\end{table}
}

编译器输出如下内容:

Not in outer par mode. \begin{table}[!htbp]
Undefined control sequence. \begin{table}[!htbp]
Missing number, treated as zero. \begin{table}[!htbp]
Overfull \hbox (0.69336pt too wide) in paragraph

参见不含的表格\adjustbox{max width=\textwidth}

输出

答案1

需要调整大小的对象\adjustboxtabular材质,不是环境table

此外,正如@egreg 在评论中指出的那样,如果您使用包的线条绘制宏,请不要使用垂直规则booktabs。实际上,仔细想想,无论您是否使用包的线条绘制宏,都不要使用垂直规则booktabs……

在此处输入图片描述

\documentclass[portuguese]{article} % or spanish?!
\usepackage{lmodern,babel,adjustbox,booktabs,multirow}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}

\begin{table}[!htbp]
\adjustbox{max width=\textwidth}{%
\centering
\begin{tabular}{@{}l*{6}{c}@{}}
\toprule
\multicolumn{1}{c}{\multirow{2}{*}{\textbf{Sub-Item}}} & 
\multirow{2}{*}{\textbf{Projeto}} & 
\multirow{2}{*}{\textbf{Processos}} & 
\multicolumn{2}{c}{\textbf{Valor individual por}} & 
\multirow{2}{*}{\textbf{Quantidade}} & 
\multirow{2}{*}{\textbf{Total}} \\ \cmidrule(lr){4-5}
 &  &  & \textbf{Projeto} & \textbf{Processo} \\ 
\midrule
Serviço de medição & 1 & 4 &  &  & 2 &  \\ %%\midrule
Serviço de apoio a projeto & 1 & 4 &  &  & 1 &  \\ 
\midrule
\multicolumn{6}{r}{\textbf{Valor total}} &  \\ 
\bottomrule
\end{tabular}}
\caption{Proposta de preço para item 1}
\label{PropostaItem1}
\end{table}

\end{document}

附录对部分或全部表格材料有两种替代规格:

  • 如果你想让你的桌子看起来更干净、更简单,即不那么浮夸,不要使用大胆的。我强烈建议你(a)摆脱大胆的\multirow标题单元格中的字体粗细以及 (b)也省去指令。

  • 使用\adjustbox使tabular类似材料适合文本块的宽度是“可行的”,但仅限于非常狭窄的意义上。\adjustbox从排版经验来看,这种方法有什么问题?最重要的是,您冒着将字体大小缩小到使表格几乎难以辨认的严重风险。因此,不要采用机械方法,而要考虑 (a) 在某些列中使用自动换行和文本换行,(b) 减少列间空白量,以及 (c) 缩短标题行中使用的标签。下面的第二个表格实现了所有三个想法。我希望您会同意,结果比上面的压缩表格更具可读性。

在此处输入图片描述

\documentclass[portuguese]{article}
\usepackage{lmodern,babel,adjustbox,booktabs,
            tabularx,ragged2e,xcolor}
\newcolumntype{L}{>{\RaggedRight\hangindent=1em \hangafter=1 \arraybackslash}X}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}

\begin{table}[!htbp]

\textcolor{red}{A\@. tabular environment, compressed}

\adjustbox{max width=\textwidth}{%
\begin{tabular}{@{}l*{6}{c}@{}}
\toprule
Sub-Item & Projeto & Processos & \multicolumn{2}{c}{Valor individual por} & Quantidade & Total \\ 
\cmidrule(lr){4-5}
 &  &  & Projeto & Processo \\ 
\midrule
Serviço de medição & 1 & 4 &  &  & 2 &  \\ %%\midrule
Serviço de apoio a projeto & 1 & 4 &  &  & 1 &  \\ 
\midrule
\multicolumn{6}{r}{Valor total} &  \\ 
\bottomrule
\end{tabular}}

\bigskip
\textcolor{red}{B\@. tabularx environment, uncompressed}

\setlength\tabcolsep{3pt} % default is 6pt
\begin{tabularx}{\textwidth}{@{}L*{6}{c}@{}}
\toprule
Sub-Item & Projeto & Processos & \multicolumn{2}{c}{Valor individual por} & Quant. & Total \\ 
\cmidrule(lr){4-5}
 &  &  & Projeto & Processo \\ 
\midrule
Serviço de medição & 1 & 4 &  &  & 2 &  \\ %%\midrule
Serviço de apoio a projeto & 1 & 4 &  &  & 1 &  \\ 
\midrule
\multicolumn{6}{r}{Valor total} &  \\ 
\bottomrule
\end{tabularx}

\end{table}

\end{document}

相关内容