6

I am new to LaTeX and don't know much about it. I am generating PDF from the LaTeX source files.

My column are very wide and I want that PDF should expand to fit the data. Does not matter how long the page is.

I am trying this. I am also setting the size to A1 but its not working

\documentclass[11pt, a1paper]{report}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}
\begin{table}
    \centering
    \caption{Table shows the commulative oxygen levels at 2 minute time intervals. The displacement is measured in \textbf{cm}}
    \begin{tabularx}{\textwidth}{@{}>{\bfseries}c*{9}{X}@{}}
    \toprule
    \hline

        \textbf{ number }

           &


        \textbf{ name }

           &


        \textbf{ job }

           &


        \textbf{ status }

           &


        \textbf{ date }

           &
user17
  • 333
  • 1
    You may try the standalone class which crops the page to its content. Full liberation for outer dimensions will bring the geometry package. If that does not meet your requirements you may consider specifying your question. Note that non-standard paper sizes may be problematic to printers. – bloodworks Apr 28 '13 at 07:56
  • i tried a3 as well. but its still cropping it. making it a4 only Also can i chnage the page orientation from portrait to landscape – user17 Apr 28 '13 at 08:01
  • 2
    Well i suppose you didn't try it the right way. A MWE would be helpful – bloodworks Apr 28 '13 at 08:05
  • Welcome to TeX.SE. Please edit the question so that it contains a fully compilable MWE. Also are you looking for the PDF to stretch in width, length, or both? – Peter Grill Apr 28 '13 at 08:19
  • @PeterGrill , i want o extend its both width and length – user17 Apr 28 '13 at 11:47

1 Answers1

6

Being as you are new to latex, I propose that you are thinking about this the wrong way.

Instead of having the PDF expand to fit the data, you could think of it like shrinking the table to fit the page size. The table can be scaled automatically, which means that you can add an arbitrary amount of data and it will always fit! smaller tables will look goofy, however, because the table will always stretch to fit the page width in my example.

Here is an example of a scaled table

\documentclass[10pt]{article}
\usepackage{fontspec}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,paperwidth=100cm,paperheight=300cm]{geometry}% Easy control of page dimensions
% paperwidth=100cm,paperheight=300cm
\usepackage{changepage}%Alter page layout
\usepackage[table]{xcolor}%Add simple color to tables

\begin{document}

\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|l|}
\hline
\rowcolor[gray]{.8}
Wrench  & Hammer & Screwdriver & Wedge & Ratchet\\
joeschmoeatgmail.com & heymisteratgmail.com & iambatmanatgmail.com & noyouarenotatgmail.com & mynameispeteratgmail.com \\
\hline
\end{tabular}}
\end{document}

Ok, let me explain what is going on here:

  • This line \documentclass[10pt]{article} sets the font to 10pt, which will be ignored in the table, because our table will be scaled inside a resizebox.
  • This package \usepackage{fontspec} is for xelatex UTF-8 support if you need it
  • This package \usepackage{geometery} can be used to set the paper type and margins (see manual for details). [] contains your parameters. The left=2cm,right=2cm,top=2cm,bottom=2cm is setting your page margins to 2cm (you can optionally set all sides with margin=2cm), while the paperwidth= and paperheight= are setting your page size to an arbitrary size. You could also check out latex guru Martin Scharrer's answer on custom page sizes here
  • This package \usepackage{changepage}can be used to change the page layout and is similar to the geometry package (see manual for details)
  • This package \usepackage[table]{xcolor} is used to add color to tables, e.g. if you want a header row accentuated.
  • The trick for automatically scaling your table is in the \resizebox{width}{height}{object} command.
    • {width} is \textwidth, the width from left margin to right margin in your current environment (which in this case is the page).
    • {height} is !, telling latexto keep the aspect ratio. You could optionally change this to some other value.
    • {object} is your table, which will be scaled according to the first two values.

You can then use either the geometry packageor the changepagepackage to control the pdf size.

David Carlisle
  • 757,742
  • why can't all people be like you. rather than explaining like you did , they point further to find the solution. thanks for your help. Is there any way to make all table columns left align. Like i am generationg headers with for loop . i have to hard code this as the num of headers {|l|l|l|l|l|l} . is there any way not to hardcode it – user17 Apr 28 '13 at 09:51
  • :) Thank you for the compliment! I know what is like to be new to latex, but remember the pros on this website are REALLY good—analogous to Sheldon Cooper. I assume you have an arbitrary number of columns, which is why you do not want to hardcode that in. I suggest you ask a NEW question and link it to this one. I would like to help you, but the admins prefer that additional questions are separated into new ones (which is logical). If my answer did indeed answer the original question, please mark it as correct by pressing the checkmark. – Jonathan Komar Apr 28 '13 at 09:57
  • i tried as written here and i get this eror ! Undefined control sequence. l.9 \resizebox – user17 Apr 28 '13 at 10:00
  • Ok, I just copied and pasted the code above into an editor and typeset it fine. I was using xelatex, but it should work fine with pdflatex. What latex engine are you usng and what version? – Jonathan Komar Apr 28 '13 at 10:02
  • i am using texlive 2012 on centos . don't know if that is version or what – user17 Apr 28 '13 at 10:05
  • I am not sure what the problem is. I cannot seem to reproduce your error, but if I am able to in the future, I will update my answer. Until then, maybe you can try bits and pieces of the code above until it does not compile correctly. You might be able to solve your problem through debugging in this way. – Jonathan Komar Apr 29 '13 at 12:09