2

It seems that I am getting imprecise values for my left and right margins. What magic is geometry doing that I am not?

My intended paper size was A4 (but as discussed in the comments and answer, this was not completely the case). I've measured 18mm left and 16mm right. Printed it without scaling it. <—just to clarify this: I printed the pdf to a physical sheet of paper and used a ruler and my near-sighted eyes.

\documentclass{article}
\usepackage{fontspec}% xelatex
\usepackage{lipsum}
\setlength{\textwidth}{\dimexpr \paperwidth - 20mm * 2 \relax}
\setlength{\oddsidemargin}{\dimexpr (\paperwidth - \textwidth)/2 - 1 in\relax}
\begin{document}
\lipsum

\lipsum
\end{document}
9
  • Using LuaLaTeX, I get exactly 20mm for each margin, measured by bringing the PDF as an image to a graphics program. My default paper is USletter.
    – user139954
    Jan 9, 2018 at 16:32
  • @RobtAll Ah cool. I am using xelatex and a4 paper. I shoulda mentioned that. Jan 9, 2018 at 16:32
  • Also 20mm with LuaLaTeX and a4 paper. Thus, the problem has something to do with XeTeX.
    – user139954
    Jan 9, 2018 at 16:37
  • is your default pdf size A4? (you may want to set \pdfpageheight and width to \paperheight and width) Jan 9, 2018 at 16:37
  • 1
    The install time option sets defaults for your pdf viewer and perhaps for the dvi to pdf driver but it does not affect latex itself which always defaults to US Letter. Jan 9, 2018 at 17:28

1 Answer 1

2

Let's see what happens.

By default, LaTeX sets paper size to US letter. If I only add to your example, after \begin{document},

\showthe\paperwidth
\showthe\textwidth
\showthe\oddsidemargin

the console shows

> 614.295pt.
l.8 \showthe\paperwidth

? 
> 500.484pt.
l.9 \showthe\textwidth

? 
> -15.36449pt.
l.10 \showthe\oddsidemargin

? 

which are exactly the same value we'd get by doing

\usepackage[left=20mm,right=20mm]{geometry}

However, xdvipdfmx is set to output to A4 paper, according to your comments. If I open the PDF file and check its properties, I get

Creator:         XeTeX output 2018.01.09:1918
Producer:       xdvipdfmx (20170318)
CreationDate:   Tue Jan  9 19:18:31 2018
Tagged:         no
Form:           none
Pages:          2
Encrypted:      no
Page size:      595.28 x 841.89 pts (A4) (rotated 0 degrees)
File size:      13853 bytes
Optimized:      no
PDF version:    1.5

which becomes

Creator:         XeTeX output 2018.01.09:1923
Producer:       xdvipdfmx (20170318)
CreationDate:   Tue Jan  9 19:23:09 2018
Tagged:         no
Form:           none
Pages:          2
Encrypted:      no
Page size:      612 x 792 pts (letter) (rotated 0 degrees)
File size:      13845 bytes
Optimized:      no
PDF version:    1.5

when geometry is loaded instead: this is because geometry informs xdvipdfmx of the output paper size.

In my measurement, the “non-geometry” version has a left margin of 20mm, and the right margin becomes 14mm. What's 612 – 595.28 (Postscript points)? It's 5.9mm.

If you instead do

\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{lipsum}
\setlength{\textwidth}{\dimexpr \paperwidth - 20mm * 2 \relax}
\setlength{\oddsidemargin}{\dimexpr (\paperwidth - \textwidth)/2 - 1 in\relax}
\begin{document}
\lipsum

\lipsum
\end{document}

you'll get the desired margins.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .