5

With some geometry options, it is possible to override a previous setting in the preamble. For example:

\documentclass{article}
\usepackage{geometry}
\geometry{hmarginratio=1:1}
\geometry{showframe,hmarginratio=6:1}

\begin{document}

  abc

\end{document}

hmarginratio switch

With others, this method does not work. For example:

\documentclass{article}
\usepackage{geometry}
\geometry{scale=.85}
\geometry{showframe,scale=.25}

\begin{document}

  abc

\end{document}

first setting sticks

Is there a good reason for this difference and is there a workaround?

The reason I'd like to do this is so that I can have a class or package set a default value for scale using \geometry{} but allow the possibility of overriding this in the document preamble.

14
  • 2
    I guess that the first scale option sets \textwidth and \textheight, so the second is ineffective because of the priority rules of section 6.3; this is however unexpected. If I look at the final values of \Gm@hscale and \Gm@vscale they are as stated (.85 in one case, .0.25 in the other).
    – egreg
    Commented Apr 24, 2015 at 21:48
  • 1
    all you need is \newgeometry{showframe,scale=.25}
    – touhami
    Commented Apr 24, 2015 at 21:53
  • @touhami I want to know if I can override it in the preamble. I cannot use \newgeometry until after \begin{document}.
    – cfr
    Commented Apr 24, 2015 at 22:43
  • Can you use AtBeginDocument or various document hooks provided etoolbox?
    – user11232
    Commented Apr 24, 2015 at 22:56
  • I mean you can use it in the preamble. It work for me
    – touhami
    Commented Apr 24, 2015 at 23:10

1 Answer 1

3

I don't think this is the full solution, but it's too long for a comment (and I've not figured out what could go wrong in here)

Looking into documenation of geometry:

reset sets back the layout dimensions and switches to the settings before geometry is loaded. Options given in geometry.cfg are also cleared. Note that this cannot reset pass and mag with truedimen. reset=false has no eect and cannot cancel the previous reset(=true) if any.

So reset might be the correct option for \geometry in preamble


\documentclass{article}
\usepackage{geometry}

\geometry{verbose,showframe,scale=.85}



\geometry{reset,verbose,showframe,scale=0.25,lmargin=2in}

\begin{document}

  abc

\end{document}

enter image description here

2
  • 1
    Thanks. I'm afraid I missed this answer because the system didn't tell me anybody had answered. If you'd not asked in chat, I wouldn't have found it. This might be helpful although, as it stands, it will undo all geometry settings, if I've understood correctly, and I only want to override the ones I explicitly set in the preamble. I'm wondering if I can use it in conjunction with some trick. (Or if I should just give this up and workaround it in some other way, which is what I ended up doing for the document I was trying to finish last night.)
    – cfr
    Commented Apr 25, 2015 at 13:22
  • 1
    @cfr: I digged somehow into geometry.sty, but it's too complicated at the moment to find the precise control flow which allows for multiple calls of \geometry and which options can be added again.
    – user31729
    Commented Apr 25, 2015 at 13:24

You must log in to answer this question.

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