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.

Hi I have a LaTeX table code generated from R like the following

\usepackage{rotating}
...
\begin{sidewaystable}
  \begin{center}
    \small\addtolength{\tabcolsep}{-7pt}
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c}
      \hline
      & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
      \hline
      1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
      2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
      3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
      4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
      \hline
    \end{tabular}
  \end{center}
\end{sidewaystable}

I have a set of tables like this. My problem is the table is not displayed in the page. So I have used two solutions 1) rotating package; 2) adding \small\addtolength{\tabcolsep}{-7pt} between \begin{center} and \begin{tabular}.

But the problem is the text in the table gets overlapped and is not legible to read. Can anyone please help me by giving a solution for this.

share|improve this question
    
Do the answers to How to Rotate a Table help? –  Jake Aug 25 '11 at 3:35
    
@Jake I have already used the \begin{sidewaystable} command to make it look better, but the problem is still i was not able to view the entire table as i have 12 columns... –  alex Aug 25 '11 at 3:41
    
Is your main aim just have the tables fit within the page boundaries? –  Werner Aug 25 '11 at 4:33

2 Answers 2

up vote 6 down vote accepted

So, there are a couple of things to consider here. Here are some possible options for fitting your style tables within the page.


[1] Enlarging the page

This is always an option. The more room on the page, the more stuff you can put on there - plain and simple. Page layout and size is easily adjusted using the geometry package.


[2] Rotating your table

Particularly for tables that are wider than they are longer/taller, rotating will save you some space and perhaps make tables fit-the-page. There are a couple of options here, depending on how you want your table caption to be placed. For example, the rotating package provides the sidewaystable environment. Also, the graphicx package provides the \rotatebox{<angle>}{<stuff>} command.


[3] Modify the font

This is actually quite radical, since typesetting of a document is all about consistency. So, changing the font may cause an inconsistency in terms of the other elements. However, preference and aesthetics is left up to the user and the content. To make it fit if it is too big you could use \small or \footnotesize or even \scriptsize.


[4] Changing the table layout

This might be last resort, but it all depends on aesthetics. Instead of keeping the table very wide, break it into two tables that are less wide, and they can possibly fit on the page a little better. Or, possibly, modify the parameters inherent to every table like the gap between columns, or the line spread.


Using the limited information at my disposal, we can use a combination of [2] and [3] via the graphicx package commands \resizebox{<h-length>}{<v-length>}{<stuff>} and \rotatebox{<angle>}{<stuff>}:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\resizebox{!}{.98\textheight}{\rotatebox{90}{%
  \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|}
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
    \multicolumn{1}{l}{} \\ \multicolumn{1}{l}{} \\ % gap between tables
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
    \multicolumn{1}{l}{} \\ \multicolumn{1}{l}{} \\ % gap between tables
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
    \multicolumn{1}{l}{} \\ \multicolumn{1}{l}{} \\ % gap between tables
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
    \multicolumn{1}{l}{} \\ \multicolumn{1}{l}{} \\ % gap between tables
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
    \multicolumn{1}{l}{} \\ \multicolumn{1}{l}{} \\ % gap between tables
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
    \multicolumn{1}{l}{} \\ \multicolumn{1}{l}{} \\ % gap between tables
    \hline
    & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
    \hline
    1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
    2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
    3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
    4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
    \hline
  \end{tabular}%
}}%

\end{document}

enter image description here

However, using the \resizebox command modifies not only the font size, but everything else - the line width of the \hline as well. Moreover, you cannot have different tables properly resized this way - my code reflects that since this is actually a single table with gaps provided by empty rows. You'll notice that the tables are specifically "shrunk" to 0.98\textheight while maintaining the aspect ratio (via !) to let them just fit within the text block of the page.

Instead (considering [4] as well) we can change the table layout by means of \setlength{\tabcolsep}{1pt} rather than \addtolength{..}{..} which would fix the column separation at 1pt. Notice the difference between the table entries and the lines:

enter image description here

Most, if not all, of these techniques depends on your style preference the rest of the document.

share|improve this answer
    
@Jake Thanks a lot for giving a solution...I will try breaking the tables. Your help is very much appreciated –  alex Aug 25 '11 at 11:35
    
Werner Thank you very much for giving the detailed explanation of various methods for fitting wider tables. It is very useful for me for the future references too. Thanks for spending your valuable time..It is very much appreciated... –  alex Aug 25 '11 at 11:38

Elaborating on part 4 of Werner's answer, Changing the Table Layout: One way to do this is to split the table in half. Here's an approach that uses the approach egreg describes in Easiest way to delete a column? to hide columns. That way, you can just copy the table, and hide different cells in the first and second table:

\documentclass{article}

\usepackage{rotating}
\usepackage{array}

\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}


\begin{document}

\begin{sidewaystable}
\raggedleft 
   \begin{tabular}{|c|c|c|c|c|c|c|HHHHHH}
      \hline
      & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
      \hline
      1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
      2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
      3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
      4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
      \hline
    \end{tabular}

\bigskip

  \begin{tabular}{HHHHHHH|c|c|c|c|c|c|}
      \hline
      & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ 
      \hline
      1 & 199431807780.64 & 183081402932.29 & 128534694388.51 & 179440680448.90 & 108197076781.65 & 197467417852.02 & 160955357155.76 & 131219625892.12 & 195614579576.07 & 124954368732.87 & 150613258150.41 & 174825984193.01 \\ 
      2 & 103291688766.33 & 122482430678.79 & 133002175739.97 & 145037559652.70 & 195323145552.54 & 127063745679.33 & 117424926743.84 & 163175808917.73 & 142332740593.70 & 141749742929.82 & 149479208537.38 & 170449046092.11 \\ 
      3 & 147147895675.15 & 141156681370.92 & 123554744524.88 & 146418996830.47 & 113873624568.81 & 180636164429.60 & 154157750261.95 & 179955205763.69 & 177509862114.68 & 184403196861.97 & 188580405595.71 & 138935472769.66 \\ 
      4 & 190173864271.49 & 100045285350.64 & 127888713567.52 & 192334005935.12 & 149804830760.70 & 110147950542.16 & 193738265451.98 & 181565890880.30 & 162375453603.45 & 109334682021.29 & 117348478571.51 & 141804601531.48 \\ 
      \hline
    \end{tabular}
\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.