# [Tex/LaTex] Shrink table with \adjustbox and handling booktabs margins

tables

I'm trying to shrink table to fit on a page (as described here) but code doesn't compile.
Also, my table has some tiny gaps in margins, how do I remove those?

My code:

\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}
}


Compiler outputs this:

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


See the table without \adjustbox{max width=\textwidth}:

The object that (potentially) has to be resized via \adjustbox is the tabular material, not the table environment.

Also, as @egreg has already pointed out in a comment, don't use vertical rules if you use the line-drawing macros of the booktabs package. Actually, coming to think of it, don't use vertical rules at all, whether or not you use the line-drawing macros of the booktabs package...

\documentclass[portuguese]{article} % or spanish?!
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\begin{document}

\begin{table}[!htbp]
\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{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}


Addendum with two alternative specifications of some or all of the tabular material:

• If you're looking to give your table an cleaner and simpler, i.e., less turgid, look, don't use bold. I strongly suggest you (a) get rid of the bold font weights in the header cells and (b) dispense with the \multirow directives as well.

• Using \adjustbox to make the tabular-like material fit inside the width of the textblock "works", but only in an extremely narrow sense. What's wrong with the \adjustbox approach, from a typographic experience? Most importantly, you run the serious risk of reducing the font size so much as to make the table well-nigh illegible. Thus, instead of taking the mechanical approach, think about (a) using automatic line breaks and text wrapping in some of the columns, (b) reducing the amount of intercolumn whitespace, and (c) shortening the labels used in the header row. The second table below implements all three ideas. I hope you will agree that the result is far more readable than the compressed table above it is.

\documentclass[portuguese]{article}
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}

\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}