TransWikia.com

Move table to fit page

TeX - LaTeX Asked by robk on May 7, 2021

I know there are several similar thready, but I couldn’t really find an answer…
I have a table that I simply can’t fit on my page. I’m a beginner with Latex and almost giving up again… This is my header:

documentclass[a4paper, fontsize=12pt]{scrreprt}
usepackage[utf8]{inputenc}
usepackage[ngerman, english]{babel}
usepackage[T1]{fontenc}
usepackage{graphicx}
graphicspath{{my_images/}}
usepackage[nottoc]{tocbibind}
usepackage[super]{nth}
usepackage{wrapfig}

defcode#1{texttt{#1}}

usepackage[backend=biber,natbib,style=apa]{biblatex}
addbibresource{references.bib}

 
usepackage{listings}

begin{document}
maketitle

thispagestyle{empty}
tableofcontents


listoffigures
letLaTeXStandardClearpageclearpage
letclearpagerelax  % Do nothing when a clearpage command appears 
listoftables
letclearpageLaTeXStandardClearpage % Return to the old definition


input{01_introduction.tex}
letLaTeXStandardClearpageclearpage
letclearpagerelax  % Do nothing when a clearpage command appears 
pagenumbering{arabic}
setcounter{page}{4}
input{02_data_methods.tex}
letclearpageLaTeXStandardClearpage % Return to the old definition
input{03_results.tex}
input{04_discussion.tex}
input{05_conclusion.tex}
printbibliography[heading=bibintoc]

end{document}

And in the 2nd input I have this table:

begin{table}[!htbp] 
  caption{} 
  label{} 
begin{tabular}{@{extracolsep{5pt}}lccccccc} 
[-1.8ex]hline 
hline [-1.8ex] 
Statistic & multicolumn{1}{c}{N} & multicolumn{1}{c}{Mean} & multicolumn{1}{c}{St. Dev.} & multicolumn{1}{c}{Min} & multicolumn{1}{c}{Pctl(25)} & multicolumn{1}{c}{Pctl(75)} & multicolumn{1}{c}{Max}  
hline [-1.8ex] 
sqft_living & 2,000 & 2,156.307 & 958.696 & 440 & 1,460 & 2,640 & 9,640  
view & 2,000 & 0.373 & 1.026 & 0 & 0 & 0 & 4  
condition & 2,000 & 3.417 & 0.654 & 1 & 3 & 4 & 5  
grade & 2,000 & 7.748 & 1.200 & 4 & 7 & 8 & 13  
yr_built & 1,800 & 1,973.880 & 28.719 & 1,900.000 & 1,954.000 & 2,000.000 & 2,014.000  
yr_renovated & 2,000 & 118.719 & 472.126 & 0 & 0 & 0 & 2,015  
sqft_living15 & 2,000 & 2,033.584 & 705.835 & 460 & 1,500 & 2,450 & 5,030  
price_per_sqft & 2,000 & 269.090 & 118.534 & 87.588 & 184.960 & 320.706 & 800.000  
lot_to_living & 2,000 & 7.154 & 15.580 & 0.544 & 2.403 & 6.488 & 281.229  
basement_percent & 2,000 & 0.127 & 0.172 & 0 & 0 & 0.3 & 1  
hline [-1.8ex] 
end{tabular} 
end{table} 

Which produces this ouput:

enter image description here

Is there anything I can do to move it a little to the left?

2 Answers

You not need to move table anyhere. Try the following:

documentclass[a4paper, fontsize=12pt]{scrreprt}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[ngerman, english]{babel}
%---------------- show page layout. don't use in a real document!
usepackage{showframe}
renewcommandShowFrameLinethickness{0.15pt}
renewcommand*ShowFrameColor{color{red}}
%---------------------------------------------------------------%

begin{document}
    begin{table}[!htbp]
caption{My huge table}
label{tab:???}
    setlengthtabcolsep{0pt}
begin{tabular*}{textwidth}{@{extracolsep{fill}}lccccccc @{}}
    hline hline
Statistic   & {N} & {Mean}  & {St. Dev.} & {Min} 
            & {Pctl(25)}    & {Pctl(75)} & {Max} 
    hline
sqft_living & 2,000 & 2,156.307 & 958.696 & 440 & 1,460 & 2,640 & 9,640 
view & 2,000 & 0.373 & 1.026 & 0 & 0 & 0 & 4 
condition & 2,000 & 3.417 & 0.654 & 1 & 3 & 4 & 5 
grade & 2,000 & 7.748 & 1.200 & 4 & 7 & 8 & 13 
yr_built & 1,800 & 1,973.880 & 28.719 & 1,900.000 & 1,954.000 & 2,000.000 & 2,014.000 
yr_renovated & 2,000 & 118.719 & 472.126 & 0 & 0 & 0 & 2,015 
sqft_living15 & 2,000 & 2,033.584 & 705.835 & 460 & 1,500 & 2,450 & 5,030 
price_per_sqft & 2,000 & 269.090 & 118.534 & 87.588 & 184.960 & 320.706 & 800.000 
lot_to_living & 2,000 & 7.154 & 15.580 & 0.544 & 2.403 & 6.488 & 281.229 
basement_percent & 2,000 & 0.127 & 0.172 & 0 & 0 & 0.3 & 1 
hline 
end{tabular*}
    end{table}
end{document}

enter image description here

(red lines show page layout)

In above MWE are:

  • for table used tabular* environment, for which width is select textwidth
  • tabcolsep is preset to zero
  • actual size of tabcolsep is left to calculation by instruction @{extracolsep{fill}}

Answered by Zarko on May 7, 2021

I suggest you get rid of the multicolumn{1}{c} cocoons that are suffocating the contents of the header cells, get rid of the @{extracolsep{5pt}} column-spacing directive, and get rid of the frankly absurd-looking decimal digits for the calendar year numbers in the min, max, Quart1, and Quart3 columns. With these adjustments, the table fits just fine.

documentclass[a4paper, fontsize=12pt]{scrreprt}
usepackage[ngerman, english]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{booktabs,array}

begin{document}
setcounter{chapter}{3} % just for this example
begin{table}[!htbp]
caption{xxx} label{tab:xxx}
centering
begin{tabular}{@{} >{ttfamily}l *{7}{c} @{}}
toprule
multicolumn{1}{@{}l}{Statistic} & $N$ & Mean & St. Dev. & Min & Pctl(25) & Pctl(75) & Max 
midrule
sqft_living & 2,000 & 2,156.307 & 958.696 & 440 & 1,460 & 2,640 & 9,640 
view & 2,000 & 0.373 & 1.026 & 0 & 0 & 0 & 4 
condition & 2,000 & 3.417 & 0.654 & 1 & 3 & 4 & 5 
grade & 2,000 & 7.748 & 1.200 & 4 & 7 & 8 & 13 
yr_built & 1,800 & 1,973.88 & 28.72 & 1900 & 1954 & 2000 & 2014 
yr_renovated & 2,000 & 118.719 & 472.126 & 0 & 0 & 0 & 2015  % why all the zeroes in this row?
sqft_living15 & 2,000 & 2,033.584 & 705.835 & 460 & 1,500 & 2,450 & 5,030 
price_per_sqft & 2,000 & 269.09 & 118.53 & 87.59 & 184.96 & 320.71 & 800.00 
lot_to_living & 2,000 & 7.154 & 15.580 & 0.544 & 2.403 & 6.488 & 281.229 
basement_percent & 2,000 & 0.127 & 0.172 & 0 & 0 & 0.3 & 1 
bottomrule
end{tabular}
end{table}

end{document}

Answered by Mico on May 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP