TeX - LaTeX Asked by byoungdoo kong on December 13, 2020
I want to control the width of my table, but the width is so long.
Could I get some ideas to fix this problem?
begin{table}
centering
caption{The examples of DTW distance for the Weizmann datasets.}
arrayrulecolor{black}
begin{tabular}{ccccccc}
toprule
two sequences & begin{tabular}[c]{@{}c@{}}boxingvs boxingend{tabular} & begin{tabular}[c]{@{}c@{}}walkingvs boxingend{tabular} & begin{tabular}[c]{@{}c@{}}runningvs boxingend{tabular} & begin{tabular}[c]{@{}c@{}}joggingvs boxingend{tabular} & begin{tabular}[c]{@{}c@{}}handwavingvs boxingend{tabular} & begin{tabular}[c]{@{}c@{}}handclappingvs boxingend{tabular}
cmidrule(lr){1-7}
DTW distance & 0.5796 & 1.7782 & 0.8616 & 1.1747 & 1.3516 & 0.969
bottomrule
end{tabular}
arrayrulecolor{black}
end{table}
You can save horizontal space by either leaving out redundant information ("vs boxing") which shouldn't be in a table anyways, or by changing the table layout from a 2x7 to a 7x2 grid. The following code shows both solutions.
The first fits in a one column document, but will still be too wide in a two column document.
documentclass[]{article}
usepackage{siunitx}
usepackage{booktabs}
begin{document}
begin{table}
centering
caption[The examples of DTW distance for the Weizmann datasets.]
{The examples of DTW distance for the Weizmann datasets. Activities shown vs
boxing.}
begin{tabular}{ccccccc}
toprule
activity & boxing & walking & running & jogging & waving & clapping
cmidrule(lr){1-7}
DTW distance & 0.5796 & 1.7782 & 0.8616 & 1.1747 & 1.3516 & 0.969
bottomrule
end{tabular}
end{table}
begin{table}
centering
caption{The examples of DTW distance for the Weizmann datasets.}
begin{tabular}{l S[table-format=1.4]}
toprule
activity vs boxing & {DTW distance}
midrule
boxing & 0.5796
walking & 1.7782
running & 0.8616
jogging & 1.1747
waving & 1.3516
clapping & 0.969
bottomrule
end{tabular}
end{table}
end{document}
Results in a one-column document:
Results in a two-column document:
Answered by Skillmon on December 13, 2020
I totally agree with the answer of Skillmon (+1) but do not answer specifically to "how to fix the width", that is, how to force a table into the text width.
At this respect you have three possible approaches: the tabular*
environment or the packages tabularx
or tabulary
. In the tree cases you must fix the width of the whole table to linewidth
:
begin{tabular?}{linewidth}{<type pf columns}}
Where ?
is *
,x
or y
and the type of columns depend on type of environment. Since
the difference between tabular* and tabularx is covered elsewhere, with tabulary
could be:
begin{tabulary}{linewidth}{@{}LCCCCCC@{}}
....
end{tabulary}
Of course, the result will be still horrendous, because you cannot fit well 7 columns in about 8 cm (assuming a standard column) with so much text, so your options are:
Reduce the font. Maybe acceptable in other cases, but in your case will only fit (more or less) with tiny,
and even then the header will need 3 or 4 lines (far from the elegance, imho).
Take the two columns for the table, using table*
, or when the behavior of starred floats is a problem, using strip
of the midfloat
package (see here). Then the result is not too bad:
documentclass[twocolumn]{article}
usepackage{lipsum,array,xcolor,booktabs,tabulary}
begin{document}
begin{table*}
centering % tiny for table
caption{The examples of DTW distance for the Weizmann datasets.}
begin{tabulary}{linewidth}{@{}LCCCCCC@{}}
toprule
Two sequences &
Boxing vs boxing &
Walking vs boxing &
Running vs boxing &
Jogging vs boxing &
Handwaving vs boxing &
Handclapping vs boxingcmidrule{1-7}
DTW distance &
0.5796 &
1.7782 &
0.8616 &
1.1747 &
1.3516 &
0.969bottomrule
end{tabulary}
end{table*}
lipsum[1-40]
end{document}
However, be able to fit in some way a table should never avoid ask yourself about the design. For instance, beside the redundant headers, really you need four decimals?
Answered by Fran on December 13, 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