0

I define a columntype which wrap its contens automatically and needs an argument for its width. As I want that my tables are exactly starting at the left margin and ending at the right one I used some kind of percentage from my textwidth. However, when summing the percentages up to 100 the table gets to wide. It is every time try and error. When having more columns I must land way under 100%, when using less columns the "aim"-value differs. Of course I could use tabularx but there were some things not working correct for my issue (to be honest I don't really can remeber what this thing was as it was far in the past).

Mayber there is some workaround that when my column-percentages ends at 1 the table is the excact width of my paper.

MWE:

\documentclass{scrbook}
\usepackage{tikz}
\usepackage[showframe,includeheadfoot, left=3cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{array} % Tabellen
\usepackage{booktabs}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % zentriert mit Breitenangabe
 \begin{document}

\begin{table}[]
\centering
\caption{My caption}
%\resizebox{\textwidth}{!}{%
\begin{tabular {C{.10\textwidth}C{.10\textwidth}C{.50\textwidth}C{.30\textwidth}}   % 100% without resizbox
\toprule
Test & Test  &Test & Test \\   \midrule
Test & Test  &Test & Test \\
Test & Test  &Test & Tes       \\ \bottomrule
\end{tabular}
%}
\end{table}

\begin{table}[]
\centering
\caption{My caption}
%\resizebox{\textwidth}{!}{%
\begin{tabular}{C{.04\textwidth}C{.04\textwidth}C{.50\textwidth}C{.30\textwidth}}   % 88% without resizebox
\toprule
Test & Test  &Test & Test \\   \midrule
Test & Test  &Test & Test \\
Test & Test  &Test & Tes       \\ \bottomrule
\end{tabular}
%}
\end{table}

\begin{table}[]
\centering
\caption{My caption}
\resizebox{\textwidth}{!}{%
\begin{tabular}{C{.10\textwidth}C{0.10\textwidth}C{.50\textwidth}C{.30\textwidth}}   % 100% with resizebox
\toprule%
Test & Test  &Test & Test \\  \midrule%
Test & Test  &Test & Test \\%
Test & Test  &Test & Tes       \\ \bottomrule%
\end{tabular}%
}
\end{table}

\end{document}

This result in this image:

  • 1) 100% without resizebox
  • 2) 88% without resizebox
  • 3) 100% with resizebox

Tables: 1) 100% without resizebox 2) 88% without resizebox 3) 100% with resizebox

When using resizebox and my value is 100% the font inside is scaled.

3

There is a gap of \tabcolsep added to both sides of each column, so for 4 columns you need another 8\tabcolsep of space (unless you put @{} between columns}.

\documentclass{scrbook}
\usepackage{tikz}
\usepackage[showframe,includeheadfoot, left=3cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{array} % Tabellen
\usepackage{booktabs}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % zentriert mit Breitenangabe

\newlength{\freewidth}

\begin{document}

\begin{table}[]
\centering
\caption{My caption}
\setlength{\freewidth}{\dimexpr\textwidth-8\tabcolsep}
\begin{tabular}{C{.10\freewidth}C{.10\freewidth}C{.50\freewidth}C{.30\freewidth}}   % 100% without resizbox
\toprule
Test & Test  &Test & Test \\   \midrule
Test & Test  &Test & Test \\
Test & Test  &Test & Tes       \\ \bottomrule
\end{tabular}
\end{table}

\end{document}

demo

3

First and foremost, don't use \resizebox on tables.

For your problem, just remove the \tabcolsep space on either side:

\documentclass{scrbook}
\usepackage{tikz}
\usepackage[showframe,includeheadfoot, left=3cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{array} % Tabellen
\usepackage{booktabs}

\newcolumntype{C}[1]{%
  >{\centering\arraybackslash}p{\dimexpr#1-2\tabcolsep}%
} % zentriert mit Breitenangabe

\begin{document}

\begin{table}[htp]
\centering

\caption{My caption}

\begin{tabular}{
  C{.10\textwidth}
  C{.10\textwidth}
  C{.50\textwidth}
  C{.30\textwidth}
}
\toprule
Test & Test  & Test & Test \\
\midrule
Test & Test  & Test & Test \\
Test & Test  & Test & Tes\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.