Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to do some absolute placement on a page but because I use pdflscape, I can't use the textpos package for this. I tried around a bit with moving with \hspace* and \vspace* but this is very tedious and produces overfull boxes galore. So I tried to change the page layout for just one page which basically works but the next page is broken in ways I cannot comprehend.

Here is what I did; I store the old dimensions, set everything to zero or whatever (pdf)LaTeX needs to make it zero and then restore the old dimensions from the saved values:

\documentclass{article}

\usepackage[english]{babel}
\usepackage{blindtext}

\newlength{\oldtextheight}
\newlength{\oldtextwidth}
\newlength{\oldevensidemargin}
\newlength{\oldoddsidemargin}
\newlength{\oldcolumnsep}
\newlength{\oldtopmargin}
\newlength{\oldheadheight}
\newlength{\oldheadsep}
\newlength{\oldfootskip}

\begin{document}

\blindtext[5]

\newpage%
% save old page dimensions
\setlength{\oldtextheight}{\textheight}%
\setlength{\oldtextwidth}{\textwidth}%
\setlength{\oldevensidemargin}{\evensidemargin}%
\setlength{\oldoddsidemargin}{\oddsidemargin}%
\setlength{\oldcolumnsep}{\columnsep}%
\setlength{\oldtopmargin}{\topmargin}%
\setlength{\oldheadheight}{\headheight}%
\setlength{\oldheadsep}{\headsep}%
\setlength{\oldfootskip}{\footskip}%
% set all margins to 0
\setlength{\textheight}{\paperheight}%
\setlength{\textwidth}{\paperwidth}%
\setlength{\evensidemargin}{-1in}%
\setlength{\oddsidemargin}{-1in}%
\setlength{\columnsep}{0pt}%
\setlength{\topmargin}{-1in}%
\setlength{\headheight}{0pt}%
\setlength{\headsep}{0pt}%
\setlength{\footskip}{0pt}%
% do absolute placement stuff where textpos doesn't work:
\noindent\rule{5mm}{5mm}\newpage% the necessity for this \newpage is also strange
% reset page dimensions
\setlength{\textheight}{\oldtextheight}%
\setlength{\textwidth}{\oldtextwidth}%
\setlength{\evensidemargin}{\oldevensidemargin}%
\setlength{\oddsidemargin}{\oldoddsidemargin}%
\setlength{\columnsep}{\oldcolumnsep}%
\setlength{\topmargin}{\oldtopmargin}%
\setlength{\headheight}{\oldheadheight}%
\setlength{\headsep}{\oldheadsep}%
\setlength{\footskip}{\oldfootskip}%
%\newpage % this wouldn't help a bit

\blindtext[10]

\end{document}

While the margins seem more or less intact, the type area is larger than the actual page. As I reset \textheight along with everything else, this makes no sense to me. The following image shows page 3 from the above example (click to enlarge):

One page later, everything is back to normal. Any help on what is happening and how I can make a clean reset would be much appreciated.

Maybe I should add that I've read that newer versions of the geometry package have \newgeometry and \restoregeometry commands that appear to do just what I'm trying to do manually but the TeXLive distribution on my current Beta Ubuntu (Precise) isn't new enough and I'd rather not mess with my package manager (it always pays me back one day) or my TeX trees in general (it's dark art and never works like it should).

I did try the gmeometric package (\geometry{textheight=\paperheight,textwidth=\paperwidth} and \geometry{textheight=\oldtextheight,textwidth=\oldtextwidth}) but to no avail.

share|improve this question
1  
Why don't you install TeX LIve 2011? –  Marco Daniel Apr 19 '12 at 16:27
1  
the geometry package is definitely a good way to go here. are you using the texlive from the repositories? if so, you'll want to get rid of it in favour of texlive 2011 from the tug website –  cmhughes Apr 19 '12 at 16:28
    
I'd rather not mess with my package manager and I don't want to install a complete (or partial for that matter) second TeX tree. If there's a well-maintained PPA that would be an option. –  Christian Apr 19 '12 at 16:29
    
After breaking my rules and messing with my package management by manually installing TeXLive and following a howto that pretended I could make it all right and explain what I did to the package manager, I got punished and spend a lot of time yesterday to get everything back to where I started. I then found this PPA launchpad.net/~texlive-backports/+archive/ppa which does a better but not perfect job of integrating with an existing Ubuntu 12.04. The good news is that the new geometry works as expected. I didn't find out what magic geometry does and I'd still be thankful for answers. –  Christian Apr 20 '12 at 5:52
1  
@Christian Indeed, the margins tag is quite appropriate here. –  lockstep May 16 '12 at 16:15
show 3 more comments

1 Answer

up vote 1 down vote accepted

If you can afford to make your code depend on a version of geometry that is not yet included in Debian, Ubuntu nor in Fedora, you can use the following code to replace the one in the question. It is much shorter to be sure.

\documentclass{article}

\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage{geometry}[2010/09/12]
\begin{document}

\blindtext[5]

\newgeometry{textheight=\paperheight,textwidth=\paperwidth}
% do absolute placement stuff where textpos doesn't work:
\noindent\rule{5mm}{5mm}
\restoregeometry

\blindtext[10]

\end{document}

I couldn't make out which trick geometry uses though. The last thing \restoregeometry does is to invoke \Gm@changelayout which just sets some lengths, some standard, some internal to geometry. Not even so much as a \clearpage.

So an answer that actually explains why the code in the question behaves so strangely would still be much appreciated and accepted as correct answer.

share|improve this answer
    
Actually, the first token executed by \restoregeometry is \clearpage. To see this, issue \show\restoregeometry and inspect your .log. Similarly, the first token executed by \newgeometry is also \clearpage. So, the behaviour of both macros is expected. –  Werner Apr 20 '12 at 6:27
    
I'm afraid I don't understand. I also do a \clearpage before setting the layout lengths. Well, actually a \newpage in the code above but I originally did a \clearpage because I needed it anyway and it showed the same broken behaviour. I just thought for the sake of a minimal example \newpage would do. –  Christian Apr 20 '12 at 8:28
    
Your MWE does not include a \newpage nor a \clearpage, so I don't know what you're commenting on. –  Werner Apr 20 '12 at 16:03
    
Maybe it's a bit hidden but: \noindent\rule{5mm}{5mm}\newpage –  Christian Apr 20 '12 at 17:12
    
BTW, if I comment out that \newpage, the length changes before that don't get applied. That's what the source code comment aimed at. Adding another \newpage after the resetting of the lengths doesn't change the broken next page a bit. I truly don't understand when the \newpage would have to go before the layout changes, when afterwards and in which cases the layout just doesn't care. Let me also again highlight the point that most lengths do take effect, just not the \textheight from the sight of it. layouts lied to my face by showing all lengths as normal. –  Christian Apr 20 '12 at 17:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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