TeX - LaTeX Asked on December 25, 2021
In order to optimize the width of some columns so that the table fits the text, I used shortstack
. Now, however, I am not satisfied with the look of the header (cf. picture). The header text in the columns in which I used shortstack
is now too close to the top hline. Furthermore, the headers where I didn’t use shortstack
are not aligned to the top hline
, which they should. Is there a way to rectify this while using shortstack
or are there better solutions to adress the width of the columns?
documentclass[12pt]{report}
usepackage{tabulary}
usepackage[maxfloats=30,morefloats=12]{morefloats}
usepackage{booktabs}
usepackage{float,lscape}
usepackage{longtable}
usepackage{pdflscape}
usepackage{tabularx}
usepackage{multirow}
usepackage{bigstrut}
begin{document}
begin{table}[htbp]
centering
caption{ETV 1830 - 1930}
tiny
begin{tabular}{rrrrrrrrr}
hline
multicolumn{1}{c}{textbf{Year}} & multicolumn{1}{c}{textbf{Organizations}} & multicolumn{1}{c}{textbf{Associations}} & multicolumn{1}{c}{textbf{shortstack{Paying\ members}}} & multicolumn{1}{c}{textbf{in % of total}} & multicolumn{1}{c}{textbf{shortstack{Non-paying\ members}}} & multicolumn{1}{c}{textbf{in % of total}} & multicolumn{1}{c}{textbf{shortstack{Total\ members}}} & multicolumn{1}{c}{textbf{shortstack{Active\ members}}} bigstrut\
hline
1830 & - & 2 & - & - & - & - & - & - bigstrut[t]\
31-40 & - & 7 & - & - & - & - & - & - \
hline
end{tabular}%
label{tab:addlabel}%
end{table}%
end{document}
In an effort to achieve your desired result with minimum changes to your original code, I added one line and changed another. I first added the line usepackage[usestackEOL]{stackengine}
to have access to the addstackgap
macro. Then, I modified your header row of the tabular
, so that one of the cramped stacks was enclosed in an addstackgap
, such as multicolumn{1}{c}{addstackgap{textbf{shortstack{Paying\ members}}}}
. This applies a 3pt vertical buffer around the object.
documentclass[12pt]{report}
usepackage{tabulary}
usepackage[maxfloats=30,morefloats=12]{morefloats}
usepackage{booktabs}
usepackage{float,lscape}
usepackage{longtable}
usepackage{pdflscape}
usepackage{tabularx}
usepackage{multirow}
usepackage{bigstrut}
usepackage[usestackEOL]{stackengine}
begin{document}
begin{table}[htbp]
centering
caption{ETV 1830 - 1930}
tiny
begin{tabular}{rrrrrrrrr}
hline
multicolumn{1}{c}{textbf{Year}} & multicolumn{1}{c}{textbf{Organizations}} & multicolumn{1}{c}{textbf{Associations}} & multicolumn{1}{c}{addstackgap{textbf{shortstack{Paying\ members}}}} & multicolumn{1}{c}{textbf{in % of total}} & multicolumn{1}{c}{textbf{shortstack{Non-paying\ members}}} & multicolumn{1}{c}{textbf{in % of total}} & multicolumn{1}{c}{textbf{shortstack{Total\ members}}} & multicolumn{1}{c}{textbf{shortstack{Active\ members}}} bigstrut\
hline
1830 & - & 2 & - & - & - & - & - & - bigstrut[t]\
31-40 & - & 7 & - & - & - & - & - & - \
hline
end{tabular}%
label{tab:addlabel}%
end{table}%
end{document}
Furthermore, if you desired the header row top-aligned, you can change every instance of shortstack
to Shortunderstack
(note the capital leading "S"), to obtain:
Answered by Steven B. Segletes on December 25, 2021
You can have what you want in a simpler way: the makecell
package allows for line breaks in cells, and a common formatting (incl. vertical alignment) in specific table cells, thanks to the thead
and makecell
commands.
To have a better vertical spacing, simply use the booktabs
package. Finally caption
produces a correct vertical spacing between caption and table when the former is above the table, and you can customise further the caption.
Thus it is possible to have a table in footnotesize
except for the column heads which are in scriptsize
– instead of tiny
, which almost unreadable:
documentclass[12pt]{report}
usepackage{tabulary}
usepackage[maxfloats=30,morefloats=12]{morefloats}
usepackage{booktabs}
usepackage{float,lscape}
usepackage{longtable}
usepackage{pdflscape}
usepackage{tabularx}
usepackage{multirow}
usepackage{bigstrut}
usepackage[showframe]{geometry}
usepackage{caption, makecell, booktabs}
captionsetup{font = footnotesize}
renewcommandtheadfont{bfseriesscriptsize}
renewcommandtheadalign{bc}
begin{document}
begin{table}[htbp]
centeringsetlengthtabcolsep{3.5pt}
caption{ETV 1830 - 1930}
footnotesize
begin{tabular}{rrrrrrrrr}
toprule
thead{Year} & thead{Organizations} & thead{Associations} & thead{Paying\ members} & thead{in %\ of total} & thead{Non-paying\ members} & thead{in %\ of total} & thead{Total\ members} & thead{shortstack{Active\ members}}\
midrule
1830 & -- & 2 & -- & -- & -- & -- & -- & -- \
addlinespace
31-40 & -- & 7 & -- & -- & -- & -- & -- & -- \
bottomrule
end{tabular}%
label{tab:addlabel}%
end{table}%
end{document}
Answered by Bernard on December 25, 2021
I do not understand why you have in preamble packages which you don't use in your MWE. So I little bit rearrange your MWE and from all package use just booktab
and tabularx
. In tabularx for table width I select textwidth
.
documentclass[12pt]{report}
% usepackage{tabulary}
% usepackage[maxfloats=30,morefloats=12]{morefloats}
usepackage{booktabs}
% usepackage{float,lscape}
% usepackage{longtable}
% usepackage{pdflscape}
usepackage{tabularx}
newcolumntype{R}{>{raggedleftarraybackslash}X}
% usepackage{multirow}
% usepackage{bigstrut}
usepackage[active,floats,tightpage]{preview}
setlengthPreviewBorder{1em}
begin{document}
begin{table}
centering
tiny
setlength{tabcolsep}{3pt}
caption{ETV 1830 - 1930}
begin{tabularx}{textwidth}{*{9}{R}}
toprule
multicolumn{1}{c}{textbf{Year}}
& multicolumn{1}{c}{textbf{Organizations}}
& multicolumn{1}{c}{textbf{Associations}}
& multicolumn{1}{c}{textbf{shortstack{Paying\ members}}}
& multicolumn{1}{c}{textbf{shortstack{in %\ of total}}}
& multicolumn{1}{c}{textbf{shortstack{Non-paying\ members}}}
& multicolumn{1}{c}{textbf{shortstack{in %\ of total}}}
& multicolumn{1}{c}{textbf{shortstack{Total\ members}}}
& multicolumn{1}{c}{textbf{shortstack{Active\ members}}}
\
midrule
1830 & - & 2 & - & - & - & - & - & - \
31-40 & - & 7 & - & - & - & - & - & - \
bottomrule
end{tabularx}%
label{tab:addlabel}%
end{table}%
end{document}
Edit: here is imege of table generated with above MWE.
Answered by Zarko on December 25, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP