Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

So I have quite a big table, as you will see in my code. I'd prefer (if possible) to have the table fit on a "normal" portrait page (personal preference as I think it is easier to read). Mainly the problem are the long headings (particularly for the last 3 columns), so perhaps wrapping text would be suitable. However if the table cannot be fitted onto a portrait page (and look reasonably pleasant!), I guess I'd have to go the horizontal page route. What would be the most suitable package to use and what would be the relevant code?

\documentclass{article}
\usepackage{booktabs, siunitx}
\begin{document}
\begin{table}[H]
\caption{Presentation of survival data for the whole sample (N = 13 298)}
\label{table:SurvivalAll}
\begin{tabular*}{\textwidth}{
!{\extracolsep{\fill}}
l
*{8}{S[table-format=2.2]} 
}
\toprule
{\bfseries Year} & {\bfseries Risk Set} & {\bfseries Graduated} & {\bfseries Academically Excluded} & {\bfseries Transferred} & {\bfseries Censored} & {\bfseries Hazard Ratio - Graduates (\%)} & {\bfseries Hazard Ratio - Academically Excluded (\%)} & {\bfseries Hazard Ratio - Transferred (\%)} \\
\midrule
1 & 13 298 & 0 & 725 & 583 & 1915 & 0.00 & 5.45 & 4.38  \\
2 & 10 075 & 0 & 474 & 176 & 1617 & 0.00 & 4.70 & 1.75 \\
3 & 7 808 & 1266 &  334 &   38 &    1030 &  16.21 & 4.28 &  0.49 \\
4 & 5 139 & 2782 &  147 &   2 & 455 &   54.14 & 2.86 &  0.04 \\
5 & 1 754 & 1135 &  76 &    2 & 205&    64.71 & 4.33 &  0.11 \\
6 & 336 &   235 &   17 &    0 & 39 &    69.94 & 5.06 &  0.00 \\ 
7 & 45 &    28 &    7 & 0 & 5 & 62.22 & 15.56 & 0.00 \\
8 & 5 & 3 & 0 & 0 & 2   & 60.00 &   0.00 &  0.00 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
share|improve this question
    
There's just too much content to fit in the page portrait-wise. The linked image has \tabcolsep set to 50% of it's original width, and all the headings are stacked, as well as the entire table is set in \small. Yet the last two column still stretch entirely out into the margin. I think going with a side-ways table is probably the only option. –  Werner Jun 5 at 19:51
    
Take a look at this if you haven't yet seen it. (in general, not too applicable here) –  WChargin Jun 7 at 4:59

3 Answers 3

up vote 20 down vote accepted

Add a legend to the caption and abbreviate the headers:

\documentclass{article}
\usepackage{booktabs, siunitx,caption}

\begin{document}
\begin{table}
\centering
\caption[Presentation of survival data for the whole sample ($N = \num{13 298}$)]
  {Presentation of survival data for the whole sample ($N = \num{13 298}$). Legend:
  Y:~Year; RS:~Risk Set; G:~Graduated; AE:~Academically Excluded;
  T:~Transferred; C:~Censored; HRG:~Hazard Ratio --~Graduates;
  HRA: Hazard Ratio --~Academically Excluded; HRT:~Hazard Ratio --~Transferred}
\label{table:SurvivalAll}
\begin{tabular}{
 @{}
 S[table-format=1.0]
 S[table-format=5.0,group-four-digits=true]
 S[table-format=4.0]
 S[table-format=3.0]
 S[table-format=3.0]
 S[table-format=4.0]
 S[table-format=2.2]
 S[table-format=2.2]
 S[table-format=1.2]
 @{}
}
\toprule
{\bfseries Y} & {\bfseries RS} & {\bfseries G} &
  {\bfseries AE} & {\bfseries T} & {\bfseries C} &
  {\bfseries HRG} & {\bfseries HRAE} & {\bfseries HRT} \\
& & & & & & {(\%)} & {(\%)} & {(\%)} \\
\midrule
1 & 13 298 &    0 & 725 & 583 & 1915 &  0.00 &  5.45 & 4.38 \\
2 & 10 075 &    0 & 474 & 176 & 1617 &  0.00 &  4.70 & 1.75 \\
3 &  7 808 & 1266 & 334 &  38 & 1030 & 16.21 &  4.28 & 0.49 \\
4 &  5 139 & 2782 & 147 &   2 &  455 & 54.14 &  2.86 & 0.04 \\
5 &  1 754 & 1135 &  76 &   2 &  205 & 64.71 &  4.33 & 0.11 \\
6 &    336 &  235 &  17 &   0 &   39 & 69.94 &  5.06 & 0.00 \\ 
7 &     45 &   28 &   7 &   0 &    5 & 62.22 & 15.56 & 0.00 \\
8 &      5 &    3 &   0 &   0 &    2 & 60.00 &  0.00 & 0.00 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

Code for both stretching the table and adding a vertical space before the legend. I'd not stretch the table, to be honest.

\documentclass{article}
\usepackage{booktabs, siunitx,caption}

\begin{document}
\begin{table}
\centering
\caption[Presentation of survival data for the whole sample ($N = \num{13 298}$)]
  {Presentation of survival data for the whole sample ($N = \num{13 298}$).\\[\medskipamount]
   Legend:
   Y:~Year; RS:~Risk Set; G:~Graduated; AE:~Academically Excluded;
   T:~Transferred; C:~Censored; HRG:~Hazard Ratio --~Graduates;
   HRA: Hazard Ratio --~Academically Excluded; HRT:~Hazard Ratio --~Transferred}
\label{table:SurvivalAll}
\begin{tabular*}{\textwidth}{
 @{\extracolsep{\fill}}
 S[table-format=1.0]
 S[table-format=5.0,group-four-digits=true]
 S[table-format=4.0]
 S[table-format=3.0]
 S[table-format=3.0]
 S[table-format=4.0]
 S[table-format=2.2]
 S[table-format=2.2]
 S[table-format=1.2]
 @{}
}
\toprule
{\bfseries Y} & {\bfseries RS} & {\bfseries G} &
  {\bfseries AE} & {\bfseries T} & {\bfseries C} &
  {\bfseries HRG} & {\bfseries HRAE} & {\bfseries HRT} \\
& & & & & & {(\%)} & {(\%)} & {(\%)} \\
\midrule
1 & 13 298 &    0 & 725 & 583 & 1915 &  0.00 &  5.45 & 4.38 \\
2 & 10 075 &    0 & 474 & 176 & 1617 &  0.00 &  4.70 & 1.75 \\
3 &  7 808 & 1266 & 334 &  38 & 1030 & 16.21 &  4.28 & 0.49 \\
4 &  5 139 & 2782 & 147 &   2 &  455 & 54.14 &  2.86 & 0.04 \\
5 &  1 754 & 1135 &  76 &   2 &  205 & 64.71 &  4.33 & 0.11 \\
6 &    336 &  235 &  17 &   0 &   39 & 69.94 &  5.06 & 0.00 \\ 
7 &     45 &   28 &   7 &   0 &    5 & 62.22 & 15.56 & 0.00 \\
8 &      5 &    3 &   0 &   0 &    2 & 60.00 &  0.00 & 0.00 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

enter image description here

share|improve this answer
    
Thanks @egreg. A nice, 'innovative' solution. Just one question (and it's just a personal preference of mine), if I wanted my table to "stretch" the width of the page (taking into account my margins), where could I put the `\textwidth' command? –  Chris Jun 6 at 8:16
    
Also there is a way to create a bit more vertical space between the title of the table ("Presentation of survival data for the whole sample (N = 13 298") and the word "Legend"? –  Chris Jun 6 at 8:53
    
@Chris I wouldn't stretch the table beyond its natural length; for the vertical space, add \\[\medskipamount] before “Legend”. I'll add an example for both. –  egreg Jun 6 at 10:24
    
I actually agree with you. However I have about 9 tables currently and the others fill the width of the page. Is there an easy command I can insert for the other tables so they have a natural width? (Obviously they have different number of columns, some don't use siuntix etc.) –  Chris Jun 6 at 10:27

perhaps

enter image description here

\documentclass{article}
\usepackage{booktabs, siunitx}
\begin{document}
\begin{table}[H]
\caption{Presentation of survival data for the whole sample (N = 13 298)}
\label{table:SurvivalAll}

\newcommand\hd[1]{\textbf{\parbox[t]{10mm}{\noindent\nobreak\hspace{0pt}\centering#1}}}
\setlength\tabcolsep{4pt}
\begin{tabular*}{\textwidth}{
!{\extracolsep{\fill}}
l
*{8}{S[table-format=2.2]} 
}
\toprule
&&&&&&\multicolumn{3}{c}{\textbf{Hazard Ratio (\%)}}\\
\hd{Year} & \hd{Risk Set} & \hd{Graduated} & \hd{Excluded} &
 \hd{Transferred} & \hd{Censored} & 
\hd{Graduates}&
 \hd{Excluded}&
\hd{Transferred} \\
\midrule
1 & 13 298 & 0 & 725 & 583 & 1915 & 0.00 & 5.45 & 4.38  \\
2 & 10 075 & 0 & 474 & 176 & 1617 & 0.00 & 4.70 & 1.75 \\
3 & 7 808 & 1266 &  334 &   38 &    1030 &  16.21 & 4.28 &  0.49 \\
4 & 5 139 & 2782 &  147 &   2 & 455 &   54.14 & 2.86 &  0.04 \\
5 & 1 754 & 1135 &  76 &    2 & 205&    64.71 & 4.33 &  0.11 \\
6 & 336 &   235 &   17 &    0 & 39 &    69.94 & 5.06 &  0.00 \\ 
7 & 45 &    28 &    7 & 0 & 5 & 62.22 & 15.56 & 0.00 \\
8 & 5 & 3 & 0 & 0 & 2   & 60.00 &   0.00 &  0.00 \\
\bottomrule
\end{tabular*}

\noindent X\dotfill X

\end{table}


\end{document}
share|improve this answer
\documentclass{article}
\usepackage{booktabs, siunitx}
\def\RB#1{\rotatebox{90}{\bfseries#1}}
\begin{document}
\begin{table}[H]
\caption{Presentation of survival data for the whole sample (N = 13 298)}
\label{table:SurvivalAll}
\centering
\begin{tabular}{@{} l 
           S[table-format=5.0]
           S[table-format=4.0]
           S[table-format=3.0]
           S[table-format=3.0]
           S[table-format=4.0]
           S[table-format=2.2]
           S[table-format=2.2]
           S[table-format=1.2] } \toprule
{\RB{Year}} & 
  {\RB{Risk Set}} & 
  {\RB{Graduated}}  & 
  {\RB{\shortstack{Academically\\Excluded}}} & 
  {\RB{Transferred}} & 
  {\RB{Censored}} & 
  {\RB{\shortstack{Hazard Ratio -\\Graduates}}} & 
  {\RB{\shortstack{Hazard Ratio -\\Academically\\ Excluded}}} & 
  {\RB{\shortstack{Hazard Ratio -\\Transferred}}} \\\midrule
1 & 13 298 & 0 & 725 & 583 & 1915 & 0.00 & 5.45 & 4.38  \\
2 & 10 075 & 0 & 474 & 176 & 1617 & 0.00 & 4.70 & 1.75 \\
3 & 7 808 & 1266 &  334 &   38 &    1030 &  16.21 & 4.28 &  0.49 \\
4 & 5 139 & 2782 &  147 &   2 & 455 &   54.14 & 2.86 &  0.04 \\
5 & 1 754 & 1135 &  76 &    2 & 205&    64.71 & 4.33 &  0.11 \\
6 & 336 &   235 &   17 &    0 & 39 &    69.94 & 5.06 &  0.00 \\ 
7 & 45 &    28 &    7 & 0 & 5 & 62.22 & 15.56 & 0.00 \\
8 & 5 & 3 & 0 & 0 & 2   & 60.00 &   0.00 &  0.00 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.