1

Is it possible to create a pdflatex document which

  • contains several pages with tables (one table per page)
  • and the page width for all pages of the pdf file is cropped to the width of the largest content (same for the height)?

I hope I was clear enough: e. g. the table on page 1 is 20 cm wide and 25 cm in height. All other pages contain tables of 19 cm width, but the table of page 10 has a height of 26 cm. So I'd like to be the page format of the whole document: 20 cm wide and 26 cm in height and all tables should be aligned in the top left corner of this page size )

  • Sounds for a job for preview together with some manual measuring which result is written to the .aux file. – Martin Scharrer Jul 2 '11 at 21:26
  • @Martin Scharrer: what does "preview" mean in this context? Is this a LaTeXpackage or a command line tool or do you mean the PDF viewer application in MacOS X? – MostlyHarmless Jul 2 '11 at 21:33
1

Prepare a file such as

\documentclass[a4paper]{article}

\usepackage[pass]{geometry}
\pagestyle{empty}

\newsavebox{\tablebox}
\newlength{\maxwidth}
\newlength{\maxheight}

\newenvironment{ftabular}
  {\begin{lrbox}{\tablebox}\begin{tabular}}
  {\end{tabular}\end{lrbox}%
   \ifdim\dimexpr\ht\tablebox+\dp\tablebox\relax>\maxheight
     \global\maxheight=\dimexpr\ht\tablebox+\dp\tablebox\relax
   \fi
   \ifdim\wd\tablebox>\maxwidth
     \global\maxwidth=\wd\tablebox
   \fi}

\begin{document}

\input{tables}

\renewenvironment{ftabular}
  {\noindent\begin{tabular}}
  {\end{tabular}\newpage}

\pdfpageheight=\maxheight
\pdfpagewidth=\maxwidth

\newgeometry{margin=0pt}

\input{tables}
\end{document}

The file tables.tex will contain your tables as

\begin{ftabular}{lll}
abc & def & ghi
\end{ftabular}

\begin{ftabular}{llp{2cm}}
pippo & pluto & paperino va al mare e fa il bagno dieci volte
\end{ftabular}

The idea is to compile the file twice; the first time we gather the sizes, the second time we print the tables. Some more work is required if you need also captions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.