Reduce column width of table while also aligning values at decimal point
with siunitx
and tabularx
(that table is fit into text area):
\documentclass[12pt, a4paper]{article}
\usepackage[format=hang,
font={small,it},
labelfont={bf,it},
labelsep=space]{caption}
\captionsetup[table]{labelsep=space,justification=raggedright,singlelinecheck=off}
\usepackage{siunitx}
\usepackage{booktabs, tabularx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[ht]
\small
\caption{Sample caption}
\label{tab:example}
%
\sisetup{parse-numbers=false,
table-format=-2.4} % integer part had to have
% one digit more than normally needed
% otherwise decimal point is overwritten
\begin{tabularx}{\linewidth}{@{} rXSSXSS @{}}
\toprule
& TEXTEXTEXT & {AR} & {t-stat} & Firms & {AR} & {t-stat} \\
\midrule
& \multicolumn{6}{l}{X TEXTEXTEXT} \\
\midrule
1 & TEXTEXTEXT & 0.0056 & (0.46) & TEXTEXTEXT & 0.0046 & (0.37) \\
2 & TEXTEXTEXT & -0.0067 & (-0.45) & TEXTEXTEXT & 0.0062 & (0.63) \\
3 & TEXTEXTEXT & 0.0006 & (0.07) & TEXTEXTEXT & -0.0036 & (-0.31) \\
4 & TEXTEXTEXT & -0.0005 & (-0.05) & TEXTEXTEXT & 0.0054 & (0.35) \\
5 & TEXTEXTEXT & 0.0029 & (0.34) & TEXTEXTEXT & 0.0046 & (0.39) \\
6 & TEXTEXTEXT & 0.0034 & (0.30) & TEXTEXTEXT & 0.0103 & (1.12) \\
7 & TEXTEXTEXT & 0.0063 & (0.38) & & & \\
8 & TEXTEXTEXT & -0.0006 & (-0.07) & & & \\
9 & TEXTEXTEXT & -0.0037 & (-0.29) & & & \\
10 & TEXTEXTEXT & -0.0017 & (-0.19) & & & \\
11 & TEXTEXTEXT & -0.0005 & (-0.06) & & & \\
12 & TEXTEXTEXT & 0.0048 & (0.57) & & & \\
13 & TEXTEXTEXT & 0.0054 & (0.52) & & & \\
14 & TEXTEXTEXT & 0.0026 & (0.25) & & & \\
\midrule
& \multicolumn{6}{l}{Y TEXTEXTEXT} \\
\midrule
1 & TEXTEXTEXT & 0.0001 & (0.01) & TEXTEXTEXT & 0.0137 & (1.59)* \\
2 & TEXTEXTEXT & -0.0014 & (-0.12) & TEXTEXTEXT & 0.0105 & (1.15) \\
3 & TEXTEXTEXT & 0.0107 & (1.48)* & TEXTEXTEXT & 0.0061 & (0.55) \\
4 & TEXTEXTEXT & 0.0040 & (0.32) & TEXTEXTEXT & 0.0109 & (0.88) \\
5 & TEXTEXTEXT & 0.0091 & (1.16) & TEXTEXTEXT & 0.0044 & (0.47) \\
6 & TEXTEXTEXT & 0.0034 & (0.41) & TEXTEXTEXT & -0.0021 & (-0.13) \\
7 & TEXTEXTEXT & -0.0014 & (-0.13) & TEXTEXTEXT & -0.0045 & (-0.35) \\
8 & TEXTEXTEXT & 0.0019 & (0.13) & TEXTEXTEXT & 0.0143 & (1.18) \\
9 & TEXTEXTEXT & 0.0001 & (0.01) & TEXTEXTEXT & -0.0160 & (-1.53)* \\
10 & TEXTEXTEXT & 0.0086 & (1.15) & TEXTEXTEXT & -0.0046 & (-0.15) \\
11 & TEXTEXTEXT & -0.0103 & (-0.98) & TEXTEXTEXT & 0.0004 & (0.04) \\
12 & TEXTEXTEXT & -0.0008 & (-0.08) & TEXTEXTEXT & -0.0015 & (-0.10) \\
13 & TEXTEXTEXT & -0.0078 & (-0.68) & TEXTEXTEXT & -0.0100 & (-0.44) \\
14 & TEXTEXTEXT & -0.0023 & (-0.14) & TEXTEXTEXT & 0.0054 & (0.65) \\
15 & TEXTEXTEXT & -0.0065 & (-0.51) & TEXTEXTEXT & 0.0018 & (0.14) \\
16 & TEXTEXTEXT & 0.0020 & (0.29) & TEXTEXTEXT & -0.0195 & (-0.91) \\
17 & TEXTEXTEXT & 0.0083 & (0.82) & & & \\
18 & TEXTEXTEXT & 0.0009 & (0.11) & & & \\
19 & TEXTEXTEXT & -0.0101 & (-0.90) & & & \\
20 & TEXTEXTEXT & 0.0043 & (0.51) & & & \\
21 & TEXTEXTEXT & 0.0072 & (0.75) & & & \\
22 & TEXTEXTEXT & -0.0211 & (-0.94) & & & \\
\bottomrule
\end{tabularx}
\raggedright\footnotesize
One-tailed t-statistics in parantheses
Signs indicate * p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01
\end{table}
\end{document}
(red lines indicate page layout)
Note: your table is to tall that can be fit in text area. This you can solve but defined bigger \textheight
(by help of the package geometry
} or using smaller font (for example \footnotesize
}
Addendum:
Inspired by \sisetup
used in @leandris answer:
\begin{table}[ht]
\footnotesize
\caption{Sample caption}
\label{tab:example}
%
\sisetup{table-space-text-pre={(},
table-align-text-pre=false,
table-space-text-post={)*},
table-align-text-post=false,
input-open-uncertainty = ,
input-close-uncertainty = ,
}
\begin{tabularx}{\linewidth}{@{} r*{2}{XS[table-format=-1.4]
S[table-format=-1.2]}
@{}}
% table body
\end{table}
gives better control over S
columns formatting. Using footnotesize
font size gives:
Here are three more possibilities:
Since your table is too tall to fit into the textblock and you specified that you didn't want to chang the margins, I'd suggest the use of longtable
. This might especially come in handy if your caption gets longer than a single line or if you decide to add more rows to your table.
In the second example, I have allowed linebreaks in column 2 and 5 and used a larger font size for the table.
In the third example, I have reduced the font size to \footnotesize
. With this, the table can fit into a single page even with a caption that has more than one or two lines.
All tables use the siunitx
package in order to align the nubers with respect to the decimal marker.
\documentclass[12pt, a4paper]{article}
\usepackage[format=hang,font={small,it},labelfont={bf,it},labelsep=space]{caption}
\captionsetup[table]{labelsep=space,justification=raggedright,singlelinecheck=off}
\usepackage{siunitx}
\usepackage{booktabs}
\sisetup{table-align-text-pre = false,
table-align-text-post = false,
input-open-uncertainty = ,
input-close-uncertainty = ,}
\usepackage{longtable} % Used for table 1
\usepackage{xltabular} % Used for table 2
\begin{document}
{\setlength{\tabcolsep}{3.25pt} \small
\begin{longtable}{@{}rlS[table-format=-1.4]SlS[table-format=-1.4]S@{}}
\caption{Sample caption that might be longer than a single line Sample caption that might be longer than a single line Sample caption that might be longer than a single line Sample caption that might be longer than a single line \label{tab:example}}\\
\toprule
& TEXTEXTEXT & {AR} & {t-stat} & Firms & {AR} & {t-stat} \\
\midrule
\endhead
\multicolumn{7}{l}{\footnotesize One-tailed t-statistics in parantheses}\\
\multicolumn{7}{l}{\footnotesize Signs indicate * p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01}
\endlastfoot
& \multicolumn{2}{l}{X TEXTEXTEXT} \\
\midrule
1 & TEXTEXTEXT & 0.0056 & (0.46) & TEXTEXTEXT & 0.0046 & (0.37) \\
2 & TEXTEXTEXT & -0.0067 & (-0.45) & TEXTEXTEXT & 0.0062 & (0.63) \\
3 & TEXTEXTEXT & 0.0006 & (0.07) & TEXTEXTEXT & -0.0036 & (-0.31) \\
4 & TEXTEXTEXT & -0.0005 & (-0.05) & TEXTEXTEXT & 0.0054 & (0.35) \\
5 & TEXTEXTEXT & 0.0029 & (0.34) & TEXTEXTEXT & 0.0046 & (0.39) \\
6 & TEXTEXTEXT & 0.0034 & (0.30) & TEXTEXTEXT & 0.0103 & (1.12) \\
7 & TEXTEXTEXT & 0.0063 & (0.38) & & & \\
8 & TEXTEXTEXT & -0.0006 & (-0.07) & & & \\
9 & TEXTEXTEXT & -0.0037 & (-0.29) & & & \\
10 & TEXTEXTEXT & -0.0017 & (-0.19) & & & \\
11 & TEXTEXTEXT & -0.0005 & (-0.06) & & & \\
12 & TEXTEXTEXT & 0.0048 & (0.57) & & & \\
13 & TEXTEXTEXT & 0.0054 & (0.52) & & & \\
14 & TEXTEXTEXT & 0.0026 & (0.25) & & & \\
\midrule
& \multicolumn{2}{l}{Y TEXTEXTEXT}\\
\midrule
1 & TEXTEXTEXT & 0.0001 & (0.01) & ATEXTEXTEXT & 0.0137 & (1.59)* \\
2 & TEXTEXTEXT & -0.0014 & (-0.12) & TEXTEXTEXT & 0.0105 & (1.15) \\
3 & TEXTEXTEXT & 0.0107 & (1.48)* & TEXTEXTEXT & 0.0061 & (0.55) \\
4 & TEXTEXTEXT & 0.0040 & (0.32) & TEXTEXTEXT & 0.0109 & (0.88) \\
5 & TEXTEXTEXT & 0.0091 & (1.16) & TEXTEXTEXT & 0.0044 & (0.47) \\
6 & TEXTEXTEXT & 0.0034 & (0.41) & TEXTEXTEXT & -0.0021 & (-0.13) \\
7 & TEXTEXTEXT & -0.0014 & (-0.13) & TEXTEXTEXT & -0.0045 & (-0.35) \\
8 & TEXTEXTEXT & 0.0019 & (0.13) & TEXTEXTEXT & 0.0143 & (1.18) \\
9 & TEXTEXTEXT & 0.0001 & (0.01) & TEXTEXTEXT & -0.0160 & (-1.53)* \\
10 & TEXTEXTEXT & 0.0086 & (1.15) & TEXTEXTEXT & -0.0046 & (-0.15) \\
11 & TEXTEXTEXT & -0.0103 & (-0.98) & TEXTEXTEXT & 0.0004 & (0.04) \\
12 & TEXTEXTEXT & -0.0008 & (-0.08) & TEXTEXTEXT & -0.0015 & (-0.10) \\
13 & TEXTEXTEXT & -0.0078 & (-0.68) & TEXTEXTEXT & -0.0100 & (-0.44) \\
14 & TEXTEXTEXT & -0.0023 & (-0.14) & TEXTEXTEXT & 0.0054 & (0.65) \\
15 & TEXTEXTEXT & -0.0065 & (-0.51) & TEXTEXTEXT & 0.0018 & (0.14) \\
16 & TEXTEXTEXT & 0.0020 & (0.29) & TEXTEXTEXT & -0.0195 & (-0.91) \\
17 & TEXTEXTEXT & 0.0083 & (0.82) & & \\
18 & TEXTEXTEXT & 0.0009 & (0.11) & & & \\
19 & TEXTEXTEXT & -0.0101 & (-0.90) & & & \\
20 & TEXTEXTEXT & 0.0043 & (0.51) & & & \\
21 & TEXTEXTEXT & 0.0072 & (0.75) & & & \\
22 & TEXTEXTEXT & -0.0211 & (-0.94) & & & \\
\bottomrule
\end{longtable}
}
\newpage
{\small
\begin{xltabular}{\textwidth}{@{}r
>{\raggedright\arraybackslash}X
S[table-format=-1.4]
S
>{\raggedright\arraybackslash}XS[table-format=-1.4]
S@{}}
\caption{Sample caption \label{tab:example2}}\\
\toprule
& TEXTEXTEXT & {AR} & {t-stat} & Firms & {AR} & {t-stat} \\
\midrule
\endhead
\multicolumn{7}{l}{\footnotesize One-tailed t-statistics in parantheses}\\
\multicolumn{7}{l}{\footnotesize Signs indicate * p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01}
\endlastfoot
& \multicolumn{3}{l}{X TEXTEXTEXT} \\
\midrule
1 & TEXTEX TEXT & 0.0056 & (0.46) & TEXTEX TEXT & 0.0046 & (0.37) \\
2 & TEXTEX TEXT & -0.0067 & (-0.45) & TEXTEX TEXT & 0.0062 & (0.63) \\
3 & TEXTEX TEXT & 0.0006 & (0.07) & TEXTEX TEXT & -0.0036 & (-0.31) \\
4 & TEXTEX TEXT & -0.0005 & (-0.05) & TEXTEX TEXT & 0.0054 & (0.35) \\
5 & TEXTEX TEXT & 0.0029 & (0.34) & TEXTEX TEXT & 0.0046 & (0.39) \\
6 & TEXTEX TEXT & 0.0034 & (0.30) & TEXTEX TEXT & 0.0103 & (1.12) \\
7 & TEXTEX TEXT & 0.0063 & (0.38) & & & \\
8 & TEXTEX TEXT & -0.0006 & (-0.07) & & & \\
9 & TEXTEX TEXT & -0.0037 & (-0.29) & & & \\
10 & TEXTEX TEXT & -0.0017 & (-0.19) & & & \\
11 & TEXTEX TEXT & -0.0005 & (-0.06) & & & \\
12 & TEXTEX TEXT & 0.0048 & (0.57) & & & \\
13 & TEXTEX TEXT & 0.0054 & (0.52) & & & \\
14 & TEXTEX TEXT & 0.0026 & (0.25) & & & \\
\midrule
& \multicolumn{3}{l}{Y TEXTEXTEXT} \\*
\midrule
1 & TEXTEX TEXT & 0.0001 & (0.01) & ATEXTEX TEXT & 0.0137 & (1.59)* \\
2 & TEXTEX TEXT & -0.0014 & (-0.12) & TEXTEX TEXT & 0.0105 & (1.15) \\
3 & TEXTEX TEXT & 0.0107 & (1.48)* & TEXTEX TEXT & 0.0061 & (0.55) \\
4 & TEXTEX TEXT & 0.0040 & (0.32) & TEXTEX TEXT & 0.0109 & (0.88) \\
5 & TEXTEX TEXT & 0.0091 & (1.16) & TEXTEX TEXT & 0.0044 & (0.47) \\
6 & TEXTEX TEXT & 0.0034 & (0.41) & TEXTEX TEXT & -0.0021 & (-0.13) \\
7 & TEXTEX TEXT & -0.0014 & (-0.13) & TEXTEX TEXT & -0.0045 & (-0.35) \\
8 & TEXTEX TEXT & 0.0019 & (0.13) & TEXTEX TEXT & 0.0143 & (1.18) \\
9 & TEXTEX TEXT & 0.0001 & (0.01) & TEXTEX TEXT & -0.0160 & (-1.53)* \\
10 & TEXTEX TEXT & 0.0086 & (1.15) & TEXTEX TEXT & -0.0046 & (-0.15) \\
11 & TEXTEX TEXT & -0.0103 & (-0.98) & TEXTEX TEXT & 0.0004 & (0.04) \\
12 & TEXTEX TEXT & -0.0008 & (-0.08) & TEXTEX TEXT & -0.0015 & (-0.10) \\
13 & TEXTEX TEXT & -0.0078 & (-0.68) & TEXTEX TEXT & -0.0100 & (-0.44) \\
14 & TEXTEX TEXT & -0.0023 & (-0.14) & TEXTEX TEXT & 0.0054 & (0.65) \\
15 & TEXTEX TEXT & -0.0065 & (-0.51) & TEXTEX TEXT & 0.0018 & (0.14) \\
16 & TEXTEX TEXT & 0.0020 & (0.29) & TEXTEX TEXT & -0.0195 & (-0.91) \\
17 & TEXTEX TEXT & 0.0083 & (0.82) & & \\
18 & TEXTEX TEXT & 0.0009 & (0.11) & & & \\
19 & TEXTEX TEXT & -0.0101 & (-0.90) & & & \\
20 & TEXTEX TEXT & 0.0043 & (0.51) & & & \\
21 & TEXTEX TEXT & 0.0072 & (0.75) & & & \\
22 & TEXTEX TEXT & -0.0211 & (-0.94) & & & \\
\bottomrule
\end{xltabular}
}
\newpage
\begin{table}[ht]
\caption{Sample caption \label{tab:example3}}
\centering
\footnotesize
\begin{tabular}{@{}rlS[table-format=-1.4]SlS[table-format=-1.4]S@{}}
\toprule
& TEXTEXTEXT & {AR} & {t-stat} & Firms & {AR} & {t-stat} \\
\midrule
& \multicolumn{2}{l}{X TEXTEXTEXT} \\
\midrule
1 & TEXTEXTEXT & 0.0056 & (0.46) & TEXTEXTEXT & 0.0046 & (0.37) \\
2 & TEXTEXTEXT & -0.0067 & (-0.45) & TEXTEXTEXT & 0.0062 & (0.63) \\
3 & TEXTEXTEXT & 0.0006 & (0.07) & TEXTEXTEXT & -0.0036 & (-0.31) \\
4 & TEXTEXTEXT & -0.0005 & (-0.05) & TEXTEXTEXT & 0.0054 & (0.35) \\
5 & TEXTEXTEXT & 0.0029 & (0.34) & TEXTEXTEXT & 0.0046 & (0.39) \\
6 & TEXTEXTEXT & 0.0034 & (0.30) & TEXTEXTEXT & 0.0103 & (1.12) \\
7 & TEXTEXTEXT & 0.0063 & (0.38) & & & \\
8 & TEXTEXTEXT & -0.0006 & (-0.07) & & & \\
9 & TEXTEXTEXT & -0.0037 & (-0.29) & & & \\
10 & TEXTEXTEXT & -0.0017 & (-0.19) & & & \\
11 & TEXTEXTEXT & -0.0005 & (-0.06) & & & \\
12 & TEXTEXTEXT & 0.0048 & (0.57) & & & \\
13 & TEXTEXTEXT & 0.0054 & (0.52) & & & \\
14 & TEXTEXTEXT & 0.0026 & (0.25) & & & \\
\midrule
& \multicolumn{2}{l}{Y TEXTEXTEXT}\\
\midrule
1 & TEXTEXTEXT & 0.0001 & (0.01) & ATEXTEXTEXT & 0.0137 & (1.59)* \\
2 & TEXTEXTEXT & -0.0014 & (-0.12) & TEXTEXTEXT & 0.0105 & (1.15) \\
3 & TEXTEXTEXT & 0.0107 & (1.48)* & TEXTEXTEXT & 0.0061 & (0.55) \\
4 & TEXTEXTEXT & 0.0040 & (0.32) & TEXTEXTEXT & 0.0109 & (0.88) \\
5 & TEXTEXTEXT & 0.0091 & (1.16) & TEXTEXTEXT & 0.0044 & (0.47) \\
6 & TEXTEXTEXT & 0.0034 & (0.41) & TEXTEXTEXT & -0.0021 & (-0.13) \\
7 & TEXTEXTEXT & -0.0014 & (-0.13) & TEXTEXTEXT & -0.0045 & (-0.35) \\
8 & TEXTEXTEXT & 0.0019 & (0.13) & TEXTEXTEXT & 0.0143 & (1.18) \\
9 & TEXTEXTEXT & 0.0001 & (0.01) & TEXTEXTEXT & -0.0160 & (-1.53)* \\
10 & TEXTEXTEXT & 0.0086 & (1.15) & TEXTEXTEXT & -0.0046 & (-0.15) \\
11 & TEXTEXTEXT & -0.0103 & (-0.98) & TEXTEXTEXT & 0.0004 & (0.04) \\
12 & TEXTEXTEXT & -0.0008 & (-0.08) & TEXTEXTEXT & -0.0015 & (-0.10) \\
13 & TEXTEXTEXT & -0.0078 & (-0.68) & TEXTEXTEXT & -0.0100 & (-0.44) \\
14 & TEXTEXTEXT & -0.0023 & (-0.14) & TEXTEXTEXT & 0.0054 & (0.65) \\
15 & TEXTEXTEXT & -0.0065 & (-0.51) & TEXTEXTEXT & 0.0018 & (0.14) \\
16 & TEXTEXTEXT & 0.0020 & (0.29) & TEXTEXTEXT & -0.0195 & (-0.91) \\
17 & TEXTEXTEXT & 0.0083 & (0.82) & & \\
18 & TEXTEXTEXT & 0.0009 & (0.11) & & & \\
19 & TEXTEXTEXT & -0.0101 & (-0.90) & & & \\
20 & TEXTEXTEXT & 0.0043 & (0.51) & & & \\
21 & TEXTEXTEXT & 0.0072 & (0.75) & & & \\
22 & TEXTEXTEXT & -0.0211 & (-0.94) & & & \\
\bottomrule
\multicolumn{7}{l}{\footnotesize One-tailed t-statistics in parantheses}\\
\multicolumn{7}{l}{\footnotesize Signs indicate * p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01}
\end{tabular}
\end{table}
\end{document}