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 latex table generated, it has 12 columns, but it is displaying only 11 columns...why is it so? Is there any mistake I am doing? Should I work something with the font size because I have another table with 12 columns but its displaying only 8 cols..it has more cell contents than this...

\documentclass{article}\begin{document}

\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrrrrrrrrrr}
\hline
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
\hline
1 & 186.30 & 101.52 & 128.33 & 148.02 & 132.08 & 138.63 & 107.98 & 133.09 & 134.12 & 119.23 & 133.21 & 165.73 \\ 
2 & 104.03 & 184.67 & 184.07 & 169.27 & 117.85 & 107.67 & 169.89 & 111.93 & 185.41 &  134.30 & 198.12 & 120.83 \\ 
3 & 170.20 & 189.47 & 142.98 & 106.06 & 116.85 & 120.74 & 100.51 & 195.18 & 196.31 & 189.16 & 180.00 & 191.78 \\ 
4 & 176.23 & 187.77 & 127.99 & 194.66 & 135.87 & 152.42 & 137.35 & 109.88 & 162.07 & 171.81 & 136.07 & 122.29 \\ 
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
share|improve this question
    
The table is larger than the textwidth and so the rest is printed in the margin. –  Marco Daniel Aug 15 '11 at 18:09
2  
It just doesn't fit on the page. Either shrink the font, rotate the table, or rearrange the data some other way so it fits. –  frabjous Aug 15 '11 at 18:11
1  
lscape from the graphics bundle or the pdflscape package could be useful for rotating, too (both @ CTAN). –  Stephen Aug 15 '11 at 18:29
add comment

2 Answers

As frabjous said in his comment, you may "[e]ither shrink the font, rotate the table, or rearrange the data some other way so it fits". Shrinking the font seems to be out of the question for your example table, as even a switch to \tiny is not sufficient to fit it into the page margins. For rotating, use the rotating package and its sidewaystable environment. (And use \centering instead of \begin{center} ... \end{center} -- here's why.)

\documentclass{article}

\usepackage{rotating}

\begin{document}

\begin{sidewaystable}
\centering
\begin{tabular}{*{13}{r}}
\hline
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
\hline
1 & 186.30 & 101.52 & 128.33 & 148.02 & 132.08 & 138.63 & 107.98 & 133.09 & 134.12 & 119.23 & 133.21 & 165.73 \\ 
2 & 104.03 & 184.67 & 184.07 & 169.27 & 117.85 & 107.67 & 169.89 & 111.93 & 185.41 &  134.30 & 198.12 & 120.83 \\ 
3 & 170.20 & 189.47 & 142.98 & 106.06 & 116.85 & 120.74 & 100.51 & 195.18 & 196.31 & 189.16 & 180.00 & 191.78 \\ 
4 & 176.23 & 187.77 & 127.99 & 194.66 & 135.87 & 152.42 & 137.35 & 109.88 & 162.07 & 171.81 & 136.07 & 122.29 \\ 
\hline
\end{tabular}
\end{sidewaystable}

\end{document}
share|improve this answer
    
@Werner thank u... –  alex Aug 15 '11 at 19:07
    
@lockstep...can we assign these functions from R.. as I got this code from R..thank u... –  alex Aug 15 '11 at 19:14
    
@alex: Sorry, I'm not familiar with R. –  lockstep Aug 15 '11 at 19:17
    
I've written functions in MATLAB to write out LaTeX versions of tables with whatever formatting I wanted, so you can probably do something similar in R. However, a 4x13 table may not be the best idea to begin with. Maybe you can make it 13 rows by 4 columns instead, or find another way of grouping the data so that it's less wide. –  Mike Renfro Aug 15 '11 at 19:24
add comment

Here are some more suggestions to make the tabular fit within your margins:


You could resize the entire table using the graphicx package command \resizebox{<h-len>}{<v-len>}{<stuff>} in the following way:

\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\resizebox{\linewidth}{!}{%
  \begin{tabular}{*{13}{r}}
  ...
  \end{tabular}%
}

The <h-len>=\linewidth will stretch/shrink the entire table to width \linewidth, while <v-len>=! keeps the aspect ratio in tact.


Modify the inter-column spacing either manually via

\begin{tabular}{*{13}{@{\hspace{<len>}}r@{\hspace{<len>}}}}% Inter-column spacing of <len>

or via setting lengths like \tabcolsep or \extracolsep. See the fixed-width table entry on the UK TeX FAQ for more details.

There are plenty more, of course. But all depend on your preference and eventual document use.

share|improve this answer
add comment

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.