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.

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

share|improve this question
    
Even at 5pt size, typesetting "Node 10" requires more than 27pt; so this table, at \tiny size will occupy much more than 600pt, which is way wider than the text width. Impossible to set at 75% of the text width. –  egreg Dec 13 '12 at 16:36
    
With that many columns you may need to consider swaping the rows and columns or rotating it for the table to be readable. You can force the table to be resized to fit the textwidth but that will resize the font as well and therefore may make the text too small to read. –  ArTourter Dec 13 '12 at 16:39
1  

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
    
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

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}
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.