14

I have a table with 23 columns. How can I fit it to the page?

Code:

\usepackage[verbose]{placeins}
\usepackage[ngerman]{babel}
\usepackage{blindtext}
    \begin{table}[htbf]
    \caption{Gross errors found using plausible value check}
    \label{tab:gr}
    \begin{center}
        \begin{tabular*}{0.75\textwidth}{@{\extracolsep{\fill}}  l  c  c c c c c c c c c c c c c c c c c c c c c c  }
           \toprule
             \textbf{Node Name} &\textbf{Node 2} &\textbf{Node 3} &\textbf{Node 4} &\textbf{Node 5} &\textbf{Node 6} &\textbf{Node 7} &\textbf{Node 8} &\textbf{Node 9} &\textbf{Node 10} &\textbf{Node 11} &\textbf{Node 12} &\textbf{Node 13} &\textbf{Node 14} &\textbf{Node 15} &\textbf{Node 17} &\textbf{Node 18} &\textbf{Node 19} &\textbf{Node 20} &\textbf{Node 25} &\textbf{Node 28} &\textbf{Node 29} &\textbf{Node 31} &\textbf{Node 32} \\
           \midrule
             \textbf{Total Number Observations} 33 & 34 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33  \\
             \textbf{Number of Faults} & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33  \\

           \bottomrule
        \end{tabular*}
    \end{center}
\end{table}
\FloatBarrier
\blindtext

Result: Result of the code Result of the code

David Carlisle
  • 757,742
ali amidi
  • 909

2 Answers2

16

Please try to ensure your question has a complete document that shows all packages used (I had to guess booktabs) and avoids unrelated errors

! Extra alignment tab has been changed to \cr.

However

enter image description here

\documentclass{article}
 \usepackage{graphicx,rotating,booktabs}

\usepackage[verbose]{placeins}
\usepackage[ngerman]{babel}
\usepackage{blindtext}


\begin{document}

    \begin{sidewaystable}[htbf]
    \caption{Gross errors found using plausible value check}
    \label{tab:gr}
  \bigskip
    \centering\small\setlength\tabcolsep{2pt}
        \hspace*{-1cm}\begin{tabular}{l  c c c c c c c c c c c c c c c c c c c c c c c  }
           \toprule
             \textbf{Name} &\textbf{2} &\textbf{3} &\textbf{4} &\textbf{5} &\textbf{6} &\textbf{7} &\textbf{8} &\textbf{9} &\textbf{10} &\textbf{11} &\textbf{12} &\textbf{13} &\textbf{14} &\textbf{15} &\textbf{17} &\textbf{18} &\textbf{19} &\textbf{20} &\textbf{25} &\textbf{28} &\textbf{29} &\textbf{31} &\textbf{32} \\
           \midrule
             \textbf{Total Number Observations} 33 & 34 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33  \\
             \textbf{Number of Faults} & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33  \\

           \bottomrule
        \end{tabular}\hspace*{-1cm}
\end{sidewaystable}
\end{document}
David Carlisle
  • 757,742
  • could you please let me know how I can manage if the table is occupying two pages? The table should have the ability to continue to the next page when it is required. – sky-light Sep 20 '16 at 23:09
  • 3
    @sky-light longtable and lscape packages are designed for that task (but it is better to ask a new question than leave a comment on a 4 year old one) – David Carlisle Sep 20 '16 at 23:14
  • Ok, I will post a question referring to this question as well. Thanks. – sky-light Sep 20 '16 at 23:16
13

You can try and spare on intercolumn spaces, by locally reducing the value of \tabcolsep; also the headers should be as short as possible.

\documentclass{article}

\usepackage[pass,showframe]{geometry} % just to show the margins
\usepackage{booktabs}

\begin{document}

Here is a table

\begin{table}[htp]
\centering
\footnotesize\setlength{\tabcolsep}{2.5pt}
\begin{tabular}{l@{\hspace{6pt}} *{22}{c}}
\toprule
\bfseries Type & \multicolumn{22}{c}{\bfseries Node name} \\
\cmidrule(l){2-23}
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & 21 & 22 \\
\midrule
\bfseries A
& 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33
& 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 \\
\bfseries B
& 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33
& 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 & 33 \\
\bottomrule
\addlinespace
\multicolumn{23}{l}{A: Total number of observations}\\
\multicolumn{23}{l}{B: Number of faults}
\end{tabular}
\caption{Observations}\label{tab:observ}
\end{table}
\end{document}

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • Is it possible to refine this code? \begin{table}[htp] \footnotesize\setlength{\tabcolsep}{2.5pt} \begin{tabular}{l@{\hspace{6pt}} *{22}{c}} \toprule \bfseries Type & \multicolumn{22}{c}{\bfseries Node name} \cmidrule(l){3-23} & 25 & 28 & 29 & 31 & 32 \midrule \bfseries TNO & 20276 & 20302 & 20267 & 20263 & 20257 \bfseries NOF & 1376 & 1321 & 83 & 1329 & 1502 \bfseries NOFI & 0 & 0 & 0 & 0 & 0 \bottomrule \addlinespace \multicolumn{23}{l}{A: Total number of observations}\multicolumn{23}{l}{B: Number of faults} \multicolumn{23}{l}{C:in 2007-09-29} \end{tabular} \end{table} – ali amidi Dec 13 '12 at 20:15
  • @aliamidi It's better if you add the data to your question so it's more easily parseable. – egreg Dec 13 '12 at 20:57
  • What do you mean by data? – ali amidi Dec 13 '12 at 21:09
  • @aliamidi The code you added in the comment. If it's in the question it can be looked at more easily. – egreg Dec 13 '12 at 21:18
  • Actually, I have used your proposed code but the problem occurred in performing. – ali amidi Dec 13 '12 at 21:30
  • @aliamidi I don't understand. But if the numbers in the table have four digits, I think it's quite hopeless to try and squeeze the table in the text width. Can you add some of the actual numbers in your example? – egreg Dec 13 '12 at 21:56
  • There are actual numbers. And I will present the table with these numbers, but the line which separate the rows is short and doesn't fit with data length. – ali amidi Dec 13 '12 at 22:09