1

This question already has an answer here:

I'm trying to set a custom paper size for my document via the geometry package. However, whenever I add the [papersize={x,y}] option, I get the wrong output. The document compiles successfully (with XeLaTeX), but the page size is not change, and additionally the margins appear all messed up (text flows past the bottom margin).

This doesn't happen on a fresh document, so I suspect the geometry package is in conflict with one of the other packages I'm using; but I can't figure out which one.

Here's a my code:

\documentclass[twoside,11pt]{memoir}

%set page dimensions
\usepackage[
xetex,
outer=1.84in,inner=0.92in, 
top=0.92in, bottom=2.1in,
papersize={8.27in,13.39in}]{geometry}

%Set English lang. 
\usepackage{polyglossia}
\setmainlanguage{english}

%enable emphasis with color instead of italics
\usepackage{xcolor}
\definecolor{ecol}{gray}{0.15}
\renewcommand\emph[1]{\textcolor{ecol}{\textbf{#1}}}

%define typeface
\usepackage{fontspec}[ligatures=tex]
\setmainfont{Baskerville}[SmallCapsFont = Bodoni 72 Smallcaps]%

\usepackage{microtype}

%figures and graphics
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{wrapfig}
\usepackage{caption}

%layout debugging
\usepackage{layout}

%for referencing labels
\usepackage[colorlinks=true, anchorcolor=red]{hyperref}

\usepackage{lipsum}

\begin{document}

\lipsum[1-20]

\end{document}

Any ideas as to what might be causing the issue?

marked as duplicate by Ulrike Fischer, Sebastiano, Bobyandbob, Stefan Pinnow, Kurt Oct 18 '18 at 11:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • See tex.stackexchange.com/questions/384945/…. You need to set \setstocksize too. The problem in your example is triggered by colorlinks as it loads color which loads the graphic-drivers. – Ulrike Fischer Oct 18 '18 at 8:50
  • @UlrikeFischer Thanks. As for the duplicate - the two questions have related answers, but I don't see how they're duplicate. Either way, thanks for the answer. I'm relatively new to using the memoir package. – johnymm Oct 18 '18 at 13:47
2

As one discovers by trimming your example, and after adding setpagesize=false option to hyperref, there is something fishy happening when colorlinks option is also used.

\documentclass[twoside,11pt]{memoir}
%\documentclass{article}

%set page dimensions
\usepackage[
%xetex,
outer=1.84in,inner=0.92in, 
top=0.92in, bottom=2.1in,
papersize={8.27in,13.39in}
]{geometry}

%Set English lang. 
%\usepackage{polyglossia}
%\setmainlanguage{english}

%enable emphasis with color instead of italics
%\usepackage{xcolor}
%\definecolor{ecol}{gray}{0.15}
%\renewcommand\emph[1]{\textcolor{ecol}{\textbf{#1}}}

%define typeface
%\usepackage{fontspec}[ligatures=tex]
%\setmainfont{Baskerville}[SmallCapsFont = Bodoni 72 Smallcaps]%

%\usepackage{microtype}

%figures and graphics
% \usepackage{graphicx}
% \usepackage{subcaption}
% \usepackage{wrapfig}
% \usepackage{caption}

%layout debugging
%\usepackage{layout}

%for referencing labels
\usepackage[setpagesize=false, 
            colorlinks=true, 
            %anchorcolor=red
]{hyperref}

\usepackage{lipsum}

\begin{document}

\lipsum[1-20]

\end{document}

With colorlinks=true commented out, one gets this

enter image description here

But with colorlinks=true active, one gets this

enter image description here

I don't know as of now what causes this. I also tested with user (not lipsum) paragraphs just to make sure there was not some weird interaction between hyperref and lipsum. It happens the same with normal non-lipsum generated text.

As you are using memoir class, I presume you have read its documentation hence perhaps try to use its own interface for page layout. (not tested)

The trimmed example can also be compiled with pdflatex with same result. It is not xetex specific. Don't pass xetex option to geometry, it knows that.


You might want to report to memoir maintainer

\documentclass{memoir}

\usepackage[papersize={10cm,25cm}]{geometry}
\usepackage[setpagesize=false,
            colorlinks=true
]{hyperref}

\begin{document}
Hello
\end{document}

displays the problem. It goes away by commenting colorlinks=true. Using the article class or book class, no problem.

\documentclass{book}

\usepackage[papersize={10cm,25cm}]{geometry}
\usepackage[setpagesize=false,
            colorlinks=true
]{hyperref}

\begin{document}
Hello
\end{document}

When using latex to examine the dvi, one finds in the colorlinks=true case (memoir class, 10cm and 25cm) the following in dvi

papersize=614.295pt,794.96999pt papersize=284.52756pt,711.3189pt papersize=614.295pt,794.96999pt

where I removed some non-ascii bytes.

With colorlinks=false or no option one sees at same location sort of in dvi:

papersize=614.295pt,794.96999pt papersize=284.52756pt,711.3189pt

Seems that colorlinks=true option of hyperref triggers a nother page setting special, but this happens with memoir not with article.



It seems that the problem is fixed simply by loading geometry after hyperref. (and setpagesize=false is then unneeded)

But I did not invest the time into debugging the root cause of the (existing) issue memoir + hyperref + geometry.



As explained by @UlrikeFischer (see https://tex.stackexchange.com/a/384952/4686 and her comment), with colorlinks=true the color package is loaded which in turn triggers usage of the graphics provided drivers.

The driver is now memoir aware and uses \stockwidth and \stockheight but geometry did no modify these lengths.

(with pdftex driver, executed at begin document)

  \ifdim\stockwidth>0pt\relax
    \ifdim\stockheight>0pt\relax
      \pdfpagewidth=\stockwidth
      \pdfpageheight=\stockheight
    \fi
  \fi

Thus hyperref is out of the loop, the following MWE triggers the issue as well:

\documentclass{memoir}

\usepackage[papersize={10cm,10cm}]{geometry}
\usepackage{graphicx}% or color package

\listfiles

\begin{document}
Hello
\end{document}

The setpagesize=false option of hyperref is without effect because it does not influence the effect of loading the graphics provided drivers after geometry.

As I recommended above the way is to use rather the memoir user interface, (this is also @daleif and @UlrikeFischer recommendations, Ulrike said in a comment:

The recommendation in my answer is to explicitly set \setstocksize{<width>}{<height>}. But David will hopefully update geometry so that this is no longer necessary in the future.

)

or load geometry last or load color first and use setpagesize=false if hyperref is last.

\documentclass{memoir}

\usepackage{color}
\usepackage[papersize={10cm,10cm}]{geometry}
\usepackage[setpagesize=false,
           colorlinks=true]{hyperref}

\listfiles

\begin{document}
Hello
\end{document}

has correct output and now setpagesize=false has an effect and is needed. So you can fix the issue by loading color early. Or better as said, use memoir own interface to page dimensions.

  • 1
    BTW I don't see any difference with geometry + hyperref with out without colorlinks option. Both give strange result. – daleif Oct 18 '18 at 9:05
  • 1
    @daleif, I trust you on this... results looked ok to me without colorlinks=true or with colorlinks=false or with geometry after hyperref... – user4686 Oct 18 '18 at 9:28
  • 1
    I just had it running with an auto updating pdf viewer. Apparently hyperref let the default stock size from memoir override the paper size given by geometry, and uses that for the paper size. – daleif Oct 18 '18 at 9:31
  • 1
    @daleif but it is strange that setpagesize=false remains without effect with hyperref (must go now...) – user4686 Oct 18 '18 at 9:32
  • 1
    I just did a full update, setpagesize=false for hyperref seems to work – daleif Oct 18 '18 at 9:51
2

I'd probably say it is an issue with geometry + hyperref vs memoir. Rather than a direct memoir issue.

It works just fine, if you use the memoir layout interface instead of geometry

\setstocksize{13.39in}{8.27in}
\settrimmedsize{\stockheight}{\stockwidth}{*}
\setlrmarginsandblock{0.92in}{1.84in}{*}
\setulmarginsandblock{0.92in}{2.1in}{*}
\checkandfixthelayout[fixed]

See the memoir manual for an explanation for fixed, I'd problably use nearest instead.


Just as a comment to @jfbu

\documentclass{memoir}
\usepackage[
papersize={10cm,20cm},
]{geometry}
\usepackage[
setpagesize=false
]{hyperref}
\usepackage{lipsum}
\begin{document}
\lipsum[1-20]
\end{document}

Gives (pdfinfo)

Creator:        LaTeX with hyperref
Producer:       pdfTeX-1.40.19
CreationDate:   Thu Oct 18 14:37:39 2018
ModDate:        Thu Oct 18 14:37:39 2018
Tagged:         no
UserProperties: no
Suspects:       no
Form:           none
JavaScript:     no
Pages:          9
Encrypted:      no
Page size:      283.465 x 566.929 pts
Page rot:       0
File size:      33104 bytes
Optimized:      no
PDF version:    1.5

Image (via Evince)

enter image description here

And

\documentclass{memoir}
\usepackage[
papersize={10cm,20cm},
]{geometry}
\usepackage[
%setpagesize=false
]{hyperref}
\usepackage{lipsum}
\begin{document}
\lipsum[1-20]
\end{document}

Creator:        LaTeX with hyperref
Producer:       pdfTeX-1.40.19
CreationDate:   Thu Oct 18 14:40:31 2018
ModDate:        Thu Oct 18 14:40:31 2018
Tagged:         no
UserProperties: no
Suspects:       no
Form:           none
JavaScript:     no
Pages:          9
Encrypted:      no
Page size:      612 x 792 pts (letter)
Page rot:       0
File size:      33115 bytes
Optimized:      no
PDF version:    1.5

Image:

enter image description here

Everything using TeXLive 2018, fully updated

  • 1
    Thanks for the posted images: I get same as yours, it means using setpagesize=false works as expected, and that was my experience. When I said it did not work, it was in the context of the colorlinks options.... (sorry for possibly not having been clear about the context of "setpagesize=false does not work") – user4686 Oct 18 '18 at 15:19

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