TeX - LaTeX Asked by aan on December 6, 2020
How can we draw a continuous vertical line using booktabs in table?
What is the simplest method to maximise the width of a table?
There are lots of methods, very confusing.
documentclass{article}
usepackage{makecell} % for bold in table using small
renewcommandtheadfont{small} % for bold in table using small
usepackage{tabularx, ragged2e}
usepackage{booktabs}
begin{document}
begin{table}[!ht]
centering
begin{tabularx}{textwidth}{l>{raggedrightarraybackslash}ccc|ccc}
toprule
& multicolumn{3}{c|}{textbf{Paired Differences1}} & multicolumn{3}{c}{textbf{Paired Differences2}}\
cmidrule{2-7}
& small {textbf{Statistic}}
& thead{small {textbf{df}}}
& thead{small {textbf{Sig.}}}
& small {textbf{Statistic}}
& thead{small {textbf{df}}}
& thead{small {textbf{Sig.}}} \
midrule
Difference & 44.20 & 14.36 & 4.54 & .957 & 10 & .746\
bottomrule
end{tabularx}
caption{Testing Testing Testing%
label{tab:test1234}%
}
end{table}
end{document}
Here is my suggestion. I have used tabular*
in combination with @{extracolsep{fill}}
to make the table as wide as the textwidth and to evenly distribute the excess white space between the columns. I have also removed the vertical line and replaced the single cmidrule
by two adjacent ones with a small white space inbetween. In order to clean up the code, I have also removed the repeated occurences ot small
and textbf
and instead added bfseries
to thedfont
:
documentclass{article}
usepackage{makecell} % for bold in table using small
renewcommandtheadfont{smallbfseries} % for bold in table using small
usepackage{tabularx, ragged2e}
usepackage{booktabs}
begin{document}
begin{table}[!ht]
begin{tabular*}{textwidth}{@{extracolsep{fill}}lcccccc}
toprule
& multicolumn{3}{c}{textbf{Paired Differences1}} & multicolumn{3}{c}{textbf{Paired Differences2}}\
cmidrule(r){2-4} cmidrule(l){5-7}
& thead{Statistic}
& thead{df}
& thead{Sig.}
& thead{Statistic}
& thead{df}
& thead{Sig.} \
midrule
Difference & 44.20 & 14.36 & 4.54 & .957 & 10 & .746\
bottomrule
end{tabular*}
caption{Testing Testing Testing%
label{tab:test1234}%
}
end{table}
end{document}
Correct answer by leandriis on December 6, 2020
With combination of S
and X
columns type, without vertical lines, with rounded numbers ... :
documentclass{article}
usepackage{booktabs, tabularx}
usepackage{xparse}
NewExpandableDocumentCommandmcx{O{1}m}
{multicolumn{#1}{>{Centeringsmallbfserieshsize=#1hsize}X}{#2}}
usepackage{ragged2e}
usepackage{siunitx}
begin{document}
begin{table}[ht]
centering
setlengthtabcolsep{0pt}
sisetup{round-integer-to-decimal,
round-mode=places,
table-format=2.2}
begin{tabularx}{linewidth}{l *{6}{S} }
toprule
& mcx[3]{Paired Differences 1}
& mcx[3]{Paired Differences 2} \
cmidrule(r){2-4}cmidrule(l){5-7}
& mcx{Statistic} & mcx{df} & mcx{Sig.}
& mcx{Statistic} & mcx{df} & mcx{Sig.} \
midrule
Difference
& 44.20 & 14.36 & 4.54 & 0.957 & 10 & 0.746 \
bottomrule
end{tabularx}
caption{Testing Testing Testing}
label{tab:test1234}
end{table}
end{document}
Answered by Zarko on December 6, 2020
I would rather replace the vertical line with a supplementary empty column to have a clear separation between the two group of columns. Another possibility, aesthetically, might be to delete the vertical padding of horizontal rules, and replace it with the makegapedcells
command from makecell
, which adds a vertical space at the top and bottom of all cells. As a demonstration, I replaced the vertical line with thick, light grey vrule, which I find more pleasing to the eye than the default thin, black, vertical rule.
documentclass{article}
usepackage{makecell} % for bold in table using small
renewcommandtheadfont{smallbfseries} % for bold in table using small
usepackage{tabularx, ragged2e}
usepackage{booktabs}
usepackage[table, svgnames]{xcolor}
begin{document}
begin{table}[!ht]
centering
begin{tabularx}{textwidth}{X>{raggedrightarraybackslash}ccccccc}
toprule
& multicolumn{3}{c}{textbf{Paired Differences1}} & & multicolumn{3}{c}{textbf{Paired Differences2}}\
cmidrule(lr){2-4} cmidrule(lr){6-8}
& thead{Statistic}
& thead{df }
& thead{ Sig. }
& & thead{Statistic}
& thead{df}
& thead{Sig.} \
midrule
Difference & 44.20 & 14.36 & 4.54 & & .957 & 10 & .746\
bottomrule
end{tabularx}
caption{Testing Testing Testing%
label{tab:test1234}%
}
end{table}
begin{table}[!ht]
centering
setlength{aboverulesep}{0pt}
setlength{belowrulesep}{0pt}
setcellgapes{3pt}makegapedcells
begin{tabularx}{textwidth}{X>{raggedrightarraybackslash}ccc!{color{Gainsboro!50!Lavender}vline width 0.75em}ccc}
toprule
& multicolumn{3}{c!{color{Gainsboro!50!Lavender}vline width 0.75em}}{textbf{Paired Differences1}} & multicolumn{3}{c}{textbf{Paired Differences2}}\noalign{vskip -0.033em}
cmidrule(lr{1.33em}){2-4} cmidrule(lr){5-7}
& thead{Statistic}
& thead{df}
& thead{Sig.}
& thead{Statistic}
& thead{df}
& thead{Sig.} \
noalign{vskip-0.05em}
cmidrule[0.05em](r{0.9em}){1-4}cmidrule[0.05em](l{0.15em}){5-7}
Difference & 44.20 & 14.36 & 4.54 & .957 & 10 & .746\
bottomrule
end{tabularx}
caption{Testing Testing Testing%
label{tab:test1234}%
}
end{table}
end{document}
Answered by Bernard on December 6, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP