1

I am trying to fit a table in Latex. My table is so wide so I tried to change the page into landscape. However, this does not work. I have used these packages:

\usepackage{amsmath}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{lscape}
\usepackage{adjustbox}

the table is :

%\begin{landscape}
%\begin{sidewaystable}
\begin{table}[ht]
\caption{My caption}
\label{my-label}
\centering
\begin{adjustbox}{width=1\textwidth}
\small
\begin{tabular}{l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\cline{2-16}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{{\bf prediction at baseline}} & \multicolumn{3}{c|}{{\bf prediction at 3 months}} & \multicolumn{3}{c|}{{\bf prediction at 6 months}} & \multicolumn{3}{c|}{{\bf prediction at 9 months}} & \multicolumn{3}{c|}{{\bf prediction for 44 patients}} \\ \cline{2-16} 
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{{\bf N = 44, n\_0 =26 n\_1 =18}} & \multicolumn{3}{c|}{{\bf N = 22, n\_0 = 13 n\_1 =9}} & \multicolumn{3}{c|}{{\bf N = 40, n\_0 =24 n\_1 =16}} & \multicolumn{3}{c|}{{\bf N = 24, n\_0 =15 n\_1 =9}} & \multicolumn{3}{c|}{{\bf N = 44, n\_0 =26 n\_1 =18}} \\ \hline
\multicolumn{1}{|l|}{Models} & {\bf Sen.\%} & {\bf Spe.\%} & {\bf ER.\%} & {\bf Sen.\%} & {\bf Spe.\%} & {\bf ER.\%} & {\bf Sen.\%} & {\bf Spe.\%} & {\bf ER.\%} & {\bf Sen.\%} & {\bf Spe.\%} & {\bf ER.\%} & {\bf Sen.\%} & {\bf Spe.\%} & {\bf ER.\%} \\ \hline
\multicolumn{1}{|l|}{{\bf Linear DA}} & 6 & 88 & 45 & 22 & 85 & 41 & 25 & 88 & 38 & 22 & 80 & 42 & 22 & 81 & 43 \\ \hline
\multicolumn{1}{|l|}{{\bf Quadratic DA}} & 17 & 88 & 41 & 56 & 77 & 32 & 88 & 67 & 25 & 89 & 80 & 17 & 78 & 73 & 25 \\ \hline
\multicolumn{1}{|l|}{{\bf Marginal Pred.}} & 22 & 88 & 39 & 22 & 92 & 36 & 75 & 92 & 15 & 78 & 93 & 13 & 67 & 92 & 18 \\ \hline
\multicolumn{1}{|l|}{{\bf Condition Pred.}} & zero & 100 & 41 & 11 & 92 & 41 & 56 & 96 & 20 & 67 & 100 & 13 & 61 & 100 & 16 \\ \hline
\multicolumn{1}{|l|}{{\bf Random effects Pred.}} & 17 & 100 & 34 & 22 & 92 & 36 & 38 & 92 & 30 & 44 & 93 & 25 & 44 & 92 & 27 \\ \hline
\end{tabular}}
\end{{adjustbox}}
\end{table}
%\end{sidewaystable}
%\end{landscape}

Or at least the table fits well in a page. could you please help me?

AboAmmar
  • 46,352
  • 4
  • 58
  • 127

2 Answers2

1

Your table is too huge to be put on a page without tiny tricks: First, you need declare test width and height with geometry package (as I do in my MWE below), second, use smaller font third, if it is allowed sffamily (they are usually a bit narrow than roman shape and fourth, reduce tabcolsep. And of course put it in sidewaytable environment.

\documentclass{article}
\usepackage[left=30mm,right=20mm,
            top=20mm,bottom=20mm,
            a4paper]{geometry}
\usepackage{amsmath}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{graphicx}
%\usepackage{lscape}
%\usepackage{adjustbox} 

\begin{document}
\begin{sidewaystable}
    \small\sffamily
    \setlength{\tabcolsep}{5pt}
    \caption{My caption}
\label{my-label}
    \centering
\begin{tabular}{|l*{15}{|c}|}
\cline{2-16}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{\textbf{prediction at baseline}} & \multicolumn{3}{c|}{\textbf{prediction at 3 months}} & \multicolumn{3}{c|}{\textbf{ prediction at 6 months}} & \multicolumn{3}{c|}{\textbf{prediction at 9 months}} & \multicolumn{3}{c|}{\textbf{prediction for 44 patients}} \\ \cline{2-16}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{\textbf{N = 44, n\_0 =26 n\_1 =18}} & \multicolumn{3}{c|}{\textbf{N = 22, n\_0 = 13 n\_1 =9}} & \multicolumn{3}{c|}{\textbf{N = 40, n\_0 =24 n\_1 =16}} & \multicolumn{3}{c|}{\textbf{N = 24, n\_0 =15 n\_1 =9}} & \multicolumn{3}{c|}{\textbf{N = 44, n\_0 =26 n\_1 =18}} \\ \hline
\multicolumn{1}{|l|}{Models} & \textbf{Sen.\%} & \textbf{Spe.\%} & \textbf{ER.\%} & \textbf{ Sen.\%} & \textbf{Spe.\%} & \textbf{ER.\%} & \textbf{Sen.\%} & \textbf{Spe.\%} & \textbf{ER.\%} & \textbf{Sen.\%} & \textbf{Spe.\%} & \textbf{ER.\%} & \textbf{Sen.\%} & \textbf{Spe.\%} & \textbf{ER.\%} \\ \hline
\multicolumn{1}{|l|}{\textbf{Linear DA}} & 6 & 88 & 45 & 22 & 85 & 41 & 25 & 88 & 38 & 22 & 80 & 42 & 22 & 81 & 43 \\ \hline
\multicolumn{1}{|l|}{\textbf{Quadratic DA}} & 17 & 88 & 41 & 56 & 77 & 32 & 88 & 67 & 25 & 89 & 80 & 17 & 78 & 73 & 25 \\ \hline
\multicolumn{1}{|l|}{\textbf{Marginal Pred.}} & 22 & 88 & 39 & 22 & 92 & 36 & 75 & 92 & 15 & 78 & 93 & 13 & 67 & 92 & 18 \\ \hline
\multicolumn{1}{|l|}{\textbf{Condition Pred.}} & zero & 100 & 41 & 11 & 92 & 41 & 56 & 96 & 20 & 67 & 100 & 13 & 61 & 100 & 16 \\ \hline
\multicolumn{1}{|l|}{\textbf{Random effects Pred.}} & 17 & 100 & 34 & 22 & 92 & 36 & 38 & 92 & 30 & 44 & 93 & 25 & 44 & 92 & 27 \\ \hline
\end{tabular}
\end{sidewaystable}  
\end{document}

If this doesn't help, you have a little reserve in second row, try to write it in two lines by help of package makcell and its macro \thead (see its documentation)

\documentclass{article}
\usepackage[left=30mm,right=20mm,
            top=20mm,bottom=20mm,
            a4paper]{geometry}
\usepackage{amsmath}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{rotating}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries\sffamily}
%\usepackage{lscape}
%\usepackage{adjustbox}

\begin{document}
\begin{sidewaystable}
    \small\sffamily
    \setlength{\tabcolsep}{5pt}
    \caption{My caption}
\label{my-label}
    \centering
\begin{tabular}{|l*{15}{|c}|}
\cline{2-16}
\multicolumn{1}{c|}{} 
    & \multicolumn{3}{c|}{\textbf{prediction at baseline}} 
        & \multicolumn{3}{c|}{\textbf{prediction at 3 months}} 
            & \multicolumn{3}{c|}{\textbf{ prediction at 6 months}} 
                & \multicolumn{3}{c|}{\textbf{prediction at 9 months}} 
                    & \multicolumn{3}{c|}{\textbf{prediction for 44 patients}} \\ \cline{2-16}
\multicolumn{1}{c|}{} 
    & \multicolumn{3}{c|}{\thead{N = 44,\\ $n_0 =26\ n_1 =18$}} 
        & \multicolumn{3}{c|}{\thead{N = 22,\\ $n_0 = 13\ n_1 =9$}} 
            & \multicolumn{3}{c|}{\thead{N = 40,\\ $n_0 =24\ n_1 =16$}} 
                & \multicolumn{3}{c|}{\thead{N = 24,\\ $n_0 =15\ n_1 =9$}} 
                    & \multicolumn{3}{c|}{\thead{N = 44, $n_0 =26\ n_1 =18$}} \\ \hline

(above is just snippet of the preamble and first two table row) or by other means.

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
Zarko
  • 296,517
0

enter image description here

\documentclass[a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{rotating}
\begin{document}

\begin{sidewaystable}
\caption{My caption}
\label{my-label}
\centering
\begin{tabular}{|l*{15}{|c}|}
\hline
\multicolumn{1}{|l|}{\textbf{Prediction}} & \multicolumn{3}{c|}{\textbf{At baseline}} & \multicolumn{3}{c|}{\textbf{At 3 months}} & \multicolumn{3}{c|}{\textbf{At 6 months}} & \multicolumn{3}{c|}{\textbf{At 9 months}} & \multicolumn{3}{c|}{\textbf{For 44 patients}} \\ \hline
\multicolumn{1}{|l|}{\textbf{(N,n\_0,n\_1)}} & \multicolumn{3}{c|}{\textbf{(44,26,18)}} & \multicolumn{3}{c|}{\textbf{(22,13,9)}} & \multicolumn{3}{c|}{\textbf{(40,24,16)}} & \multicolumn{3}{c|}{\textbf{(24,15,9)}} & \multicolumn{3}{c|}{\textbf{(44,26,18)}} \\ \hline
\multicolumn{1}{|l|}{\textbf{Models (\%)}} & \textbf{Sen.} & \textbf{Spe.} & \textbf{ER.} & \textbf{ Sen.} & \textbf{Spe.} & \textbf{ER.} & \textbf{Sen.} & \textbf{Spe.} & \textbf{ER.} & \textbf{Sen.} & \textbf{Spe.} & \textbf{ER.} & \textbf{Sen.} & \textbf{Spe.} & \textbf{ER.} \\ \hline
\multicolumn{1}{|l|}{\textbf{Linear DA}} & 6 & 88 & 45 & 22 & 85 & 41 & 25 & 88 & 38 & 22 & 80 & 42 & 22 & 81 & 43 \\ \hline
\multicolumn{1}{|l|}{\textbf{Quadratic DA}} & 17 & 88 & 41 & 56 & 77 & 32 & 88 & 67 & 25 & 89 & 80 & 17 & 78 & 73 & 25 \\ \hline
\multicolumn{1}{|l|}{\textbf{Marginal Pred.}} & 22 & 88 & 39 & 22 & 92 & 36 & 75 & 92 & 15 & 78 & 93 & 13 & 67 & 92 & 18 \\ \hline
\multicolumn{1}{|l|}{\textbf{Condition Pred.}} & zero & 100 & 41 & 11 & 92 & 41 & 56 & 96 & 20 & 67 & 100 & 13 & 61 & 100 & 16 \\ \hline
\multicolumn{1}{|l|}{\textbf{Random effects Pred.}} & 17 & 100 & 34 & 22 & 92 & 36 & 38 & 92 & 30 & 44 & 93 & 25 & 44 & 92 & 27 \\ \hline
\end{tabular}
\end{sidewaystable}  

\end{document}

My main idea is to remove unnecessary repetition of words and entries. Specifically, %, Prediction, (N,n_0,n_1) are all repeated. This alone can make the table fit well in a single page. Further reductions can be made as those suggested by @Zarko.

For beauty, you can also consider using booktabs.

AboAmmar
  • 46,352
  • 4
  • 58
  • 127