2

I Have several tables in one document which I need to fit to the page. The Problem is that it overflows horizontally and while trying to scale it automatically with \resizebox or \adjustbox the only effect is: they are getting smaller and smaller by every table.

tried the proposed codings of the links below, but unfortunately its still not working for the whole document.

  1. How to align table so that it doesn't overflow the page horizontally
  2. How to shrink a table automatically so that it fits onto a page?
  3. Latex table goes out of page border

May anyone will be able to solve this issue? Many thanks in advance!

Here is the original idea of the table without \resizebox etc.:

     \documentclass[%
      paper=A4,             
      pagesize=auto,          
      BCOR=1cm,               
      DIV=classic,            
      fontsize=12pt,            
      headings=normal,      
      bibliography=totoc,       
      titlepage=on,         
      captions=tableheading,    
      captions=oneline,       
      numbers=noendperiod,    
      toc=listof,             
      draft=false               
    ]{scrartcl} 
     \usepackage{calc}                              
    \usepackage{pifont}                            
    \usepackage{ifthen}                            
    \usepackage{enumerate}                         
    \usepackage[round]{natbib}                     
    \usepackage[english,ngerman]{babel}            
    \usepackage[centertags,fleqn]{amsmath}         
    \usepackage{textcomp}                          
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}                  
    \usepackage[bitstream-charter]{mathdesign}     
    \usepackage{sourcesanspro}                     
    \usepackage{microtype}                         
    \usepackage{srcltx}                            
    \usepackage{fancyvrb}                          
    \usepackage[final]{graphicx}                   
    \usepackage{color}                             
    \usepackage{caption}                           
    \usepackage{dcolumn}                           
    \usepackage{booktabs}                          
    \usepackage[right, official]{eurosym}          
    \usepackage{scrlayer-scrpage}                  
    \usepackage{hyperref}  
    \usepackage{graphicx}                        
    \usepackage{adjustbox}                      
    \usepackage{tabularx}                           

    \begin{document}

    %\setlength{\extrarowheight}{2pt}
    %\setlength{\tabcolsep}{2\tabcolsep}
    \begin{table}[htbp]\caption{Effects My-Modell\label{Tab3.4}}
    \begin{centering}
    \begin{tabularx}{\textwidth}{l......}\toprule
    \multicolumn{1}{c}{$\eta\textbackslash\sigma$} &
    \multicolumn{1}{c}{$0.0036$} &
    \multicolumn{1}{c}{$0.0072$} &
    \multicolumn{1}{c}{$0.0108$}  &
    \multicolumn{1}{c}{$0.0144$}  &
    \multicolumn{1}{c}{$0.0180$}  &
    \multicolumn{1}{c}{$0.0216$}\\\midrule
    $1.1$&0.001317&0.005266&0.011850&0.021067& 0.032920&0.047409\\
     &  0.003601    &   0.014406    &   0.032416    &   0.057637    &   0.090073    &   0.129734\\
    $2.0$&     -0.001071   & -0.004285   &   -0.009640   &   -0.017137  &  -0.026774     & -0.038549 \\
    &0.002354   &   0.009416    &   0.021188    &   0.037674    &   0.058878    &   0.084807\\
    $3.0$&     -0.002988   &  -0.011950  &  -0.026882   &  -0.047775   &  -0.074619& -0.107398\\
    &   0.002352    &   0.009408    &   0.021171    &   0.037646    &   0.058841    &   0.084764\\
    $4.0$&     -0.004882   &  -0.019524  &   -0.043908   &  -0.078005   &  -0.121777&-0.175171\\
    &0.002790   &   0.011162    &   0.025121    &   0.044676    &   0.069842    &   0.100635\\
    $5.0$&    -0.006818    & -0.027258   &   -0.061278   &  -0.108810 & -0.169756  & -0.243994 \\
    &   0.003604    &   0.014421    &   0.032462    &   0.057748    &   0.090304    &   0.130167\\
    $6.0$&     -0.008789   & -0.035126   &   -0.078931   &   -0.140064  &  -0.218335 & -0.313502\\
    &   0.004802    &   0.019217    &   0.043270    &   0.077002    &   0.120473    &   0.173758\\
    $7.0$&     -0.010781 & -0.043075   &  -0.096736  &   -0.171524   &  -0.267108   &  -0.383068\\
    &   0.006431    &   0.025742    &   0.057985    &   0.103248    &   0.161654    &   0.233365\\
    $8.0$&     -0.012780 & -0.051042   &  -0.114552  &   -0.202928   &  -0.315641   &  -0.452031\\
    &   0.008524    &   0.034132    &   0.076929    &   0.137092    &   0.214872    &   0.310596\\
    $9.0$&     -0.014772   &  -0.058971  &   -0.132248   &  -0.234028   &  -0.315641 &  -0.519781\\
    &   0.011043    &   0.044237    &   0.099781    &   0.178012    &   0.279410    &   0.404607\\
    $10.0$&   -0.016747 &   -0.066821 &   -0.149723   &  -0.264610   & -0.410474 & -0.585862\\
    &   0.014061    &   0.056362    &   0.127264    &   0.227377    &   0.357582    &   0.519048\\\bottomrule
    \multicolumn{7}{p{18cm}}{%
    \scriptsize{\bfseries Notes:} Effects in Percent. Here is an explanation of the table, the parameters, the measurement etc. Its quite long and has also to be fitted text width to the table.%
    }
    \end{tabularx}
    \end{centering}
    \end{table}
    \end{document}
  • 1
    (i) your question is for sure duplicate ... so any help will be actually off-topic (ii) to help you, you need to provide complete but small document where in preamble are defined all your commands. (iii) welcime to tex.se! – Zarko Feb 7 '18 at 17:46
  • Off-topic: The hyperref package should be loaded last. – Mico Feb 7 '18 at 19:03
4

Here's another solution. It's quite similar to @Zarko's in the use of the S column type for the six numeric columns, to align all numbers on their respective decimal markers. It differs from @Zarko's solution in (a) the use of a tabular* environment, (b) the provision of more visual structure to the header material, and (c) no reliance on the threeparttable package and its eponymous environment.

For sure, your table isn't all that wide. No need to take any heroic measures to make the table fit inside the width of the textblock.

enter image description here

    \documentclass[%
      paper=A4,pagesize=auto,BCOR=1cm,               
      DIV=classic,fontsize=12pt,headings=normal,      
      bibliography=totoc,titlepage=on,         
      captions=tableheading,captions=oneline,       
      numbers=noendperiod,toc=listof,draft=false               
      ]{scrartcl} 
    \usepackage{calc,pifont,ifthen,enumerate}                         
    \usepackage[round]{natbib}                     
    \usepackage[english,ngerman]{babel}            
    \usepackage[centertags,fleqn]{amsmath}         
    \usepackage{textcomp}                          
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}                  
    \usepackage[bitstream-charter]{mathdesign}     
    \usepackage{sourcesanspro,microtype,srcltx,fancyvrb}                          
    \usepackage[final]{graphicx}                   
    \usepackage{color,caption,siunitx,booktabs}                          
    \usepackage[right, official]{eurosym}          
    \usepackage{scrlayer-scrpage,graphicx,adjustbox,tabularx}
    \usepackage{hyperref}   % load this package last!

\begin{document}

\begin{table}[htbp]
\small
\caption{Effects My-Modell} \label{Tab3.4}
\sisetup{table-format=-1.6,group-digits=false}
\setlength\tabcolsep{0pt} % let LaTeX figure out intercolumn whitespace
\begin{tabular*}{\textwidth}{ @{\extracolsep{\fill}}
       S[table-format=2.1] *{6}{S} }
\toprule
    {$\eta$} & 
    \multicolumn{6}{c}{$\sigma$} \\
    \cmidrule{2-7}
& 0.0036 & 0.0072 & 0.0108 & 0.0144 & 0.0180 & 0.0216 \\
\midrule
    1.1& 0.001317& 0.005266& 0.011850& 0.021067& 0.032920& 0.047409\\
       & 0.003601& 0.014406& 0.032416& 0.057637& 0.090073& 0.129734\\
    2.0&-0.001071&-0.004285&-0.009640&-0.017137&-0.026774&-0.038549\\
       & 0.002354& 0.009416& 0.021188& 0.037674& 0.058878& 0.084807\\
    3.0&-0.002988&-0.011950&-0.026882&-0.047775&-0.074619&-0.107398\\
       & 0.002352& 0.009408& 0.021171& 0.037646& 0.058841& 0.084764\\
    4.0&-0.004882&-0.019524&-0.043908&-0.078005&-0.121777&-0.175171\\
       & 0.002790& 0.011162& 0.025121& 0.044676& 0.069842& 0.100635\\
    5.0&-0.006818&-0.027258&-0.061278&-0.108810&-0.169756&-0.243994\\
       & 0.003604& 0.014421& 0.032462& 0.057748& 0.090304& 0.130167\\
    6.0&-0.008789&-0.035126&-0.078931&-0.140064&-0.218335&-0.313502\\
       & 0.004802& 0.019217& 0.043270& 0.077002& 0.120473& 0.173758\\
    7.0&-0.010781&-0.043075&-0.096736&-0.171524&-0.267108&-0.383068\\
       & 0.006431& 0.025742& 0.057985& 0.103248& 0.161654& 0.233365\\
    8.0&-0.012780&-0.051042&-0.114552&-0.202928&-0.315641&-0.452031\\
       & 0.008524& 0.034132& 0.076929& 0.137092& 0.214872& 0.310596\\
    9.0&-0.014772&-0.058971&-0.132248&-0.234028&-0.315641&-0.519781\\
       & 0.011043& 0.044237& 0.099781& 0.178012& 0.279410& 0.404607\\
   10.0&-0.016747&-0.066821&-0.149723&-0.264610&-0.410474&-0.585862\\
       & 0.014061& 0.056362& 0.127264& 0.227377& 0.357582& 0.519048\\
\bottomrule
\end{tabular*}

\smallskip
\footnotesize\textbf{Notes:} Effects in Percent. Here is an explanation 
    of the table, the parameters, the measurement etc. It's quite long
    and also has to fit inside the width of the textblock.
\end{table}

\end{document}
  • header of table is really better than mine (+1)! – Zarko Feb 7 '18 at 18:51
  • Thanks a lot! Its working for all tables in the whole document now. Great Work! Thanks again! – aranjues Feb 8 '18 at 11:57
3

your table with is not longer than text width ... i would:

  • for column type use S column type from siunitx package
  • instead tabularx use tabular
  • remove all \multicolumn{1}{c}{...}
  • for notes use threepartable and its macro tablenotes (your problmes is cause by multicolumn{7}{p{18cm}{...} which is wide than text width)
  • for test purposes i add showframe which with red lines indicate page layout. in real document you had to remove it.

\documentclass{scrartcl}
\usepackage{booktabs, threeparttable}
\usepackage{siunitx}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{table}[htb]
\centering
\begin{threeparttable}
    \caption{Effects My-Modell}
    \label{Tab3.4}
\begin{tabular}{S[table-format=2.1]
           *{6}{S[table-format=-1.6]}}
\toprule
{$\eta\textbackslash\sigma$} 
    &   0.0036  &   0.0072  &   0.0108  &   0.0144  &   0.0180  &   0.0216  \\
\midrule
1.1 & 0.001317  & 0.005266  & 0.011850  & 0.021067  & 0.032920  & 0.047409  \\
    & 0.003601  & 0.014406  & 0.032416  & 0.057637  & 0.090073  & 0.129734  \\
2.0 &-0.001071  &-0.004285  &-0.009640  &-0.017137  &-0.026774  & -0.038549 \\
    & 0.002354  & 0.009416  & 0.021188  & 0.037674  & 0.058878  &  0.084807 \\
3.0 &-0.002988  &-0.011950  &-0.026882  &-0.047775  &-0.074619  &-0.107398  \\
    & 0.002352  & 0.009408  & 0.021171  & 0.037646  & 0.058841  & 0.084764  \\
4.0 &-0.004882  &-0.019524  &-0.043908  &-0.078005  &-0.121777  &-0.175171  \\
    & 0.002790  & 0.011162  & 0.025121  & 0.044676  & 0.069842  & 0.100635  \\
5.0 &-0.006818  &-0.027258  &-0.061278  &-0.108810  &-0.169756  &-0.243994  \\
    & 0.003604  & 0.014421  & 0.032462  & 0.057748  & 0.090304  & 0.130167  \\
6.0 &-0.008789  &-0.035126  &-0.078931  &-0.140064  &-0.218335  &-0.313502  \\
    & 0.004802  & 0.019217  & 0.043270  & 0.077002  & 0.120473  & 0.173758  \\
7.0 &-0.010781  &-0.043075  &-0.096736  &-0.171524  &-0.267108  &-0.383068  \\
    & 0.006431  & 0.025742  & 0.057985  & 0.103248  & 0.161654  & 0.233365  \\
8.0 &-0.012780  &-0.051042  &-0.114552  &-0.202928  &-0.315641  &-0.452031  \\
    & 0.008524  & 0.034132  & 0.076929  & 0.137092  & 0.214872  & 0.310596  \\
9.0 &-0.014772  &-0.058971  &-0.132248  &-0.234028  &-0.315641  &-0.519781  \\
    & 0.011043  & 0.044237  & 0.099781  & 0.178012  & 0.279410  & 0.404607  \\
10.0&-0.016747  &-0.066821  &-0.149723  &-0.264610  &-0.410474  &-0.585862  \\
    &0.014061   & 0.056362  & 0.127264  & 0.227377  & 0.357582  & 0.519048  \\
    \bottomrule
\end{tabular}
\begin{tablenotes}[para,flushleft]\footnotesize
\textbf{Notes:} Effects in Percent. Here is an explanation of the table, the parameters, the measurement etc. Its quite long and has also to be fitted text width to the table.%
\end{tablenotes}
\end{threeparttable}
    \end{table}
\end{document}

enter image description here

  • Thanks a lot for your help. unfortunately the table is overflowing the page again. the code from @Mico is working pretty good. so problem is solved. thanks again! – aranjues Feb 8 '18 at 12:09
  • your claim is only partial truth. as you can see, table in answer fit text width. however, i made answer before you provide mwe, so this time i haven't any idea about your page layout. later you not notice me, that you edit your question. – Zarko Feb 8 '18 at 13:03
  • please excuse the inaccuracy. it was my fault not to post the preamble and after your advice ii) I added it to the post. so again big thanks for your help! – aranjues Feb 9 '18 at 8:42
2

I don't think you need to use tabularx, but a simple tabular with S column, for an alignment of the numbers on the decimal dot. I also suggest to group the rows by pairs, adding an extra spacing between rows, and the use the tablenotes environment from threeparttable so the notes fit the table width.

 \documentclass[%
  paper=A4,
  pagesize=auto,
  BCOR=1cm,
  DIV=classic,
  fontsize=12pt,
  headings=normal,
  bibliography=totoc,
  titlepage=on,
  captions=tableheading,
  captions=oneline,
  numbers=noendperiod,
  toc=listof,
  draft=false,
  english,ngerman
]{scrartcl}
\usepackage{scrlayer-scrpage}

    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}

    \usepackage{amsmath, amssymb}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{sourcesanspro}
\usepackage{microtype}

 \usepackage{babel}
    \usepackage[showframe]{geometry}

    \usepackage{array}
    \usepackage{caption, booktabs, threeparttable}
    \captionsetup{labelfont=sc}
    \usepackage{tabularx}
    \usepackage{siunitx}
    \usepackage{makebox} 
    \usepackage{makecell}
    \renewcommand\theadfont{\bfseries}
    \setcellgapes[t]{5pt}
    \makegapedcells \newcommand\niet{\multicolumn{1}{c}{---}}

    \begin{document}

    \begin{table}[htbp]
\sisetup{table-format = -1.6,table-number-alignment = center}
    \centering
\setlength{\tabcolsep}{3pt}
\begin{threeparttable}
    \caption{Effects My-Modell\label{Tab3.4}}
    \begin{tabular}{@{}S[table-format = 2.2]*{6}{S}}
 \toprule\addlinespace[0.5ex]
 {\makebox[2em][r]{\rlap{$\sigma$}}} &
 {$0.0036$} &
 {$0.0072$} &
 {$0.0108$} &
 {$0.0144$} &
 {$0.0180$} &
 {$0.0216$}\\[-0.5ex]
 {\makebox*{$10.0$}{$\eta$}} \\\midrule
 1.1&0.001317&0.005266&0.011850&0.021067& 0.032920&0.047409 \\
 & 0.003601 & 0.014406 & 0.032416 & 0.057637 & 0.090073 & 0.129734 \\[0.7ex]
  2.0 & -0.001071 & -0.004285 & -0.009640 & -0.017137 & -0.026774 & -0.038549 \\
 &0.002354 & 0.009416 & 0.021188 & 0.037674 & 0.058878 & 0.084807 \\[0.7ex]
 3.0& -0.002988 & -0.011950 & -0.026882 & -0.047775 & -0.074619& -0.107398 \\
 & 0.002352 & 0.009408 & 0.021171 & 0.037646 & 0.058841 & 0.084764 \\[0.7ex]
 4.0& -0.004882 & -0.019524 & -0.043908 & -0.078005 & -0.121777&-0.175171 \\
 &0.002790 & 0.011162 & 0.025121 & 0.044676 & 0.069842 & 0.100635 \\[0.7ex]
 5.0& -0.006818 & -0.027258 & -0.061278 & -0.108810 & -0.169756 & -0.243994 \\
 & 0.003604 & 0.014421 & 0.032462 & 0.057748 & 0.090304 & 0.130167 \\[0.7ex]
 6.0& -0.008789 & -0.035126 & -0.078931 & -0.140064 & -0.218335 & -0.313502 \\
 & 0.004802 & 0.019217 & 0.043270 & 0.077002 & 0.120473 & 0.173758 \\[0.7ex]
 7.0& -0.010781 & -0.043075 & -0.096736 & -0.171524 & -0.267108 & -0.383068 \\
 & 0.006431 & 0.025742 & 0.057985 & 0.103248 & 0.161654 & 0.233365 \\[0.7ex]
 8.0& -0.012780 & -0.051042 & -0.114552 & -0.202928 & -0.315641 & -0.452031 \\
 & 0.008524 & 0.034132 & 0.076929 & 0.137092 & 0.214872 & 0.310596 \\[0.7ex]
 9.0& -0.014772 & -0.058971 & -0.132248 & -0.234028 & -0.315641 & -0.519781 \\
 & 0.011043 & 0.044237 & 0.099781 & 0.178012 & 0.279410 & 0.404607 \\[0.7ex]
 10.0& -0.016747 & -0.066821 & -0.149723 & -0.264610 & -0.410474 & -0.585862 \\
 & 0.014061 & 0.056362 & 0.127264 & 0.227377 & 0.357582 & 0.519048\\
    \bottomrule
    \end{tabular}
\smallskip
\begin{tablenotes}[online]
 \scriptsize\item[\bfseries Notes:] Effects in Percent. Here is an explanation of the table, the parameters, the measurement etc. It’s quite long and has also to be fitted text width to the table.%
\end{tablenotes}
\end{threeparttable}
    \end{table}

    \end{document}

enter image description here

  • @Mico: the \niet command is only a residue of my starting point to answer (initially the O.P. didn't post a full code, so I used the preamble of another answer, and didn't notice this command). I've deleted it. As to the \textbackslash, you think the intention was a something like a slashbox in the first cell of the table? – Bernard Feb 8 '18 at 13:49
  • Indeed, I suspect the OP's objective was to create a slashbox-like impression. (See, e.g, Zarko's answer for the result of not deleting \textbackslash...) Because slashbox doesn't work all well with the line-drawing macros of the booktabs package, I chose to reorganize the header thoroughly. I may have (or may not have) guessed the OP's intent correctly... – Mico Feb 8 '18 at 13:54
  • I wrote a comment to Zarkos post and asked for an apology for the inaccuracy. So I will do here. It was my fault not to post the preamble. The guess, indeed, was correct. the idea was to get a slashbox. So again big thanks to your work! You all helped a lot to get a better understanding of the packages! I can't repeat often enough, Thanks a lot. Great Job! – aranjues Feb 9 '18 at 8:50

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.