TeX - LaTeX Asked by ngm on February 23, 2021
I used the following code to create a longtable with five columns that stretches the full width of the page. I like everything about this table except for the fact that all columns are padded to make the table as wide as the page. Instead, I would like the first four columns to expand in this way, but I would like the fifth column (the one with header D) to be "sized to content". That is, I would like it to be only as wide as it needs to be to fit its values.
documentclass[table]{article}
usepackage{fancyhdr}
usepackage[left=0.50in,top=2.0in,right=0.50in,bottom=1.0in]{geometry}
setlengthparindent{0pt}
usepackage{longtable}
usepackage{pdflscape}
begin{document}
setlengthLTleft{0pt}
setlengthLTright{0pt}
begin{longtable}{l @{extracolsep{fill}} | r|r|r|r}
multicolumn{5}{r}{bfseries {Large{My Table}}}
& {bfseries A}
& {bfseries B}
& {bfseries C}
& {bfseries D}
endfirsthead
multicolumn{5}{r}{bfseries {Large{My Table (continued)}}}
% name
& {bfseries A}
& {bfseries B}
& {bfseries C}
& {bfseries D}
hline
endhead
hline
hspace{4mm} Row 1 hspace{2mm}
& 1,200
& 800
& 2,000
& 1
hspace{4mm} Row 2 hspace{2mm}
& 1,201
& 801
& 2,001
& 123
end{longtable}
end{document}
How it currently looks:
My crude approximation of how it should look:
Is there a way to do this?
Like this:
documentclass{article}
%usepackage{fancyhdr}
usepackage[hmargin=0.50in,top=2.0in,bottom=1.0in]{geometry}
setlengthparindent{0pt}
usepackage{array, longtable}
%usepackage{pdflscape}
begin{document}
%setlengthLTleft{0pt}
%setlengthLTright{0pt}
begin{longtable}{@{qquad}l| *{3}{>{raggedleft}p{0.25linewidth}|} r}
multicolumn{5}{r}{bfseries {Large{My Table}}}
& {bfseries A}
& {bfseries B}
& {bfseries C}
& {bfseries D}
endfirsthead
multicolumn{5}{r}{bfseries {Large{My Table (continued)}}}
% name
& {bfseries A}
& {bfseries B}
& {bfseries C}
& {bfseries D}
hline
endhead
hline
Row 1 & 1,200
& 800
& 2,000
& 1
Row 2 & 1,201
& 801
& 2,001
& 123
end{longtable}
end{document}
Correct answer by Zarko on February 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP