2

Recently a fellow student asked me how to make a table over the entire width of the page. I don't know why he wanted to do that but I thought it should be easy and wrote the following example:

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}

\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}

\noindent
\makebox[\linewidth][c]{%
\begin{tabularx}{\paperwidth}{XCR}
    \toprule
    x   & x   & x   \\
    xx  & xx  & xx  \\
    xxx & xxx & xxx \\
    \bottomrule
\end{tabularx}%
}

\end{document}

However, the table was too wide (the grey part is the background of my pdf viewer): enter image description here


I have printed the value of \paperwidth using a \convertto macro taken from another answer:

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother
\convertto{mm}{\paperwidth}mm

It says the value of \paperwidth is 215.90114mm. But the size of the resulting pdf is according to my viewer A4, Portrait (210 × 297 mm) -- as it should be.

I am using pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex 2017.4.22) and Evince Document Viewer 3.14.1.

How can it be that \paperwidth and the width of the resulting document do not match?

  • \paperwidth defaults to USletter size unless you use [a4paper] option – David Carlisle Dec 5 '17 at 10:21
  • The default paper size for the standard classes (article, report, book) letter paper. Therefore, class option a4paper is needed. – Heiko Oberdiek Dec 5 '17 at 10:22
  • @DavidCarlisle, @HeikoOberdiek yes, thank you. With the a4paper class option the table fits as expected. So \paperwidth is independent of the size of the output document? That seems counterintuitive... – jakun Dec 5 '17 at 11:18
  • @jakun: No, the output document should comply to \paperwidth and friends, AFAIK. Maybe your viewer displays it as A4? – Martin Scharrer Dec 5 '17 at 11:39
  • latex (unless you use graphics, or hyperref or geometry or similar driver specific packages) has no driver specific code so \papersize is used to set various tex lengths but it is not used to set the media box in the resulting pdf, that is your system default (a4 or us letter normally) If you add \usepackage{graphics} then the driver specials or pdftex primitives are used to force the pdf media box to match, then your document would have fitted on the page, but the page in your preview would have been us letter sized. – David Carlisle Dec 5 '17 at 12:07
3

You are seeing the default layout of latex (which is for US Letter) displayed at your default pdf media page (which in your case is A4).

You should use [a4paper] to tell LaTex that you are using A4 and/or you should add

\usepackage{graphicx}

(or hyperref, or geometry) as these packages will detect the tex engine or driver options in use and add system-specific code to force the media box of the resulting PDF to match the declared page size in latex.

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.