2

My table extends past the margin of my .pdf file. I already set the margin using the geometry package. How will I be able to adjust the width of my table so that it will be within the specified margins?

Reg
  • 79
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Aug 24 '14 at 03:48
  • 1
    The width of a table necessarily depends on its content ;-) –  Aug 24 '14 at 03:57
  • 2
    Exactly what @ChristianHupfer said. If you are using the l, r, or c column types perhaps you can use the p{<width>} type for some of the wider columns. Or perhaps scale the table as per How to fit a wide table, or reduce inter-column spacing But a specific solution will depend on you actual use case so best to put together a MWE that represents your problem table. – Peter Grill Aug 24 '14 at 04:17
  • I managed to fix the width of my table using p{} type. My problem now is that all my text is aligned to the left. I need most of my text to be center aligned. I tried using \multicolumn{1}{|c|}{content} for each cell, but it disregarded the parameters I set in the p{}. How will I be able to center align my text while keeping the specified parameters? – Reg Aug 24 '14 at 06:45
  • 1
    @Reg so please show us your MWE to see how are you working with that table and can help you. – Aradnix Aug 24 '14 at 07:05

1 Answers1

2

You wrote in a comment:

I managed to fix the width of my table using p{<width>} type. My problem now is that all my text is aligned to the left. I need most of my text to be center aligned.

To define a column type that center-sets its contents and takes a width specifier, you could add the following code to your preamble

\usepackage{array}     % for \newcolumntype macro
\usepackage{ragged2e}  % for \Centering macro
\newcolumntype{C}[1]{>{\Centering\arraybackslash}p{#1}}

Then, use the C column type instead the p column type for those columns whose contents should be center-set. (By the way, the p column type fully justifies its contents; your comment would appear to suggest that it left-aligns its contents.)

Aside: The advantage of using \Centering instead of \centering is that hyphenation of words will be allowed. If you want to suppress hyphenation within the C columns, use the \centering directive instead.

Mico
  • 506,678