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 am looking for "global" and "local" solutions to the case where I have a table that goes "much" beyond the right and left margins of the page (meaning: cases where having no margins to the page would not solve the problem).

Such solution can include:

  • Reducing the font size of the text inside the table.
  • Making the table cells to implement some sort of "wordwrap" solution. (I found such a solution here.)

I would appreciate any help with mentioning other solutions that I might have overlooked, and on how to implement the two options I mentioned above.

share|improve this question
    
Place it in a box and scale it \scalebox{\textwidth}{... your table here}. –  Yiannis Lazarides Feb 3 '12 at 17:48
    
Another option would be tabularx or tabulary. Also, one could modify the horizontal column padding. –  Werner Feb 3 '12 at 18:02
    
@YiannisLazarides This is really frowned upon in my opnion, unless the table contains something that nobody would read, but in that case you don't need that table. –  tohecz Feb 3 '12 at 18:03
2  
On of the best things you can to is to use sidewaystable floating environment from rotating package. This allows the table to be typeset rotated, hence having much larger width. In the case the table is too long as well, you can combine it with longtable package and split the table to multiple pages. –  tohecz Feb 3 '12 at 18:06
    
@tohecz I am also not very fond of such solutions, but given a well designed table that needs 3-5% correction this is an acceptable solution. Without seeing the table it is difficult to say. –  Yiannis Lazarides Feb 3 '12 at 18:08

3 Answers 3

The tabularx package provides the tabularx environment with the format

\begin{tabularx}{<width>}{<col spec>}
  % tabularx contents
\end{tabularx}

It also provides the X column type that stretches the column to fill the remaining length of <width> given the other elements in <col spec>. It is most often used with <width> given as \linewidth (or \textwidth) which allows the table to fit within the text block horizontally.

A similar approach and interface exists when using the tabulary package.


Another attempt at fitting the table within the text block margin (horizontally) would be to modify the padding inserted between columns. This is given by \tabcolsep. Default is 6pt for the standard document classes. However, reducing this might only help if the table is marginally too large.

share|improve this answer
1  
actually latex puts in 2\tabcolsep even without the rules so the spacing isn't increased that much. In standard tabular it doesn't increase at all as the rules overprint the tabskip glue. In array package based environments the spacing is increased by the width of the ruke. –  David Carlisle Feb 3 '12 at 19:50
    
@DavidCarlisle: Thanks for correcting me! –  Werner Feb 3 '12 at 19:57

Once I had a package that measured the table and tried in turn normal, sideways, smaller font or longtable to see what fitted best. Not sure what happened to that, I think it is on ctan somewhere:-). If you want the column widths to adjust to the amount of data in the column tabulary is probably better than tabularx.

share|improve this answer
    
Hi David, How can I decide between tabulary and tabularx? –  Tal Galili Feb 3 '12 at 19:49
    
@TalGalili How do you decide between blue and green:-) They are just different, both aim to make a table of a specified width, TX aims to distribute the widths evenly over the columns, TY aims to chose column widths to make the colums with more data wider. In any given case, if you chose one, you'll wish you used the other. –  David Carlisle Feb 3 '12 at 20:28

to do this with tabularx: 1. on lyx go to documents -> settings -> Latex preamble. there should be a text box there. put this text in the box:

%% Hack by Heiko Oberdiek (on de.comp.text.tex)
\usepackage{tabularx}

%% Redefine the standard table
\let\ORIGtabular\tabular
\let\ORIGendtabular\endtabular
\let\ORIGtabularx\tabularx
\renewcommand*{\tabularx}{%
  \def\tabular{%
    \let\endtabular\ORIGendtabular
    \ORIGtabular
  }%
  \ORIGtabularx
}

\renewcommand{\tabular}{%
%% The width of the table. Adjust if needed
  \tabularx{\linewidth}%
}

\renewcommand{\endtabular}{\endtabularx} 

now click OK.

  1. create your table.
  2. right click the table and go to more -> settings -> Table settings under column settings, find the box next to "latex argument" and write "X" in it.
  3. you may need to repeat this for every column of your table.

done! this should evenly spread all columns within the line width.

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.