# Attempts to manually change \linewidth ignored by LaTeX [closed]

I was going to try to answer the question: How can I change the geometry of a page on the chapter header page only, and return to normal on the next page? It didn't seem like it should be too difficult (despite the comments of some). Well, it turned out to be exceptionally difficult and very frustrating.

# Using the geometry package

Using geometry, it's easy to go into a document and manually change the margins etc. and easy to restore things. In the preamble, you simple invoke:

\usepackage[margin=1in]{geometry}


If you want to change this temporarily, you can write:

\savegeometry{mydefaultgeometry}
\newgeometry{margin=3in}


And then later you can call:

\loadgeometry{mydefaultgeometry}


I thought the solution to OP's questions might be simply solved through some finagling of the page shipout. I tried a number of approaches. I tried using atbegshi, everyshi, and afterpage. All to no effect.

# It's a local vs. global issue

Then I got an idea: maybe this was a problem of locally defined vs. globally defined values etc. I decided to test this out with something simple to verify:

\newcommand{\myname}{AEllett}


Here's the MWE I tried with afterpage:

\documentclass{report}
\usepackage{afterpage}
\usepackage{lipsum}
%%
\newcommand{\myname}{AEllett}
\newcommand{\mychapter}[1]{%
\chapter{#1}%
\afterpage{\renewcommand{\myname}{someone else's name}}%
}
%% loading fancy to test whether \renewcommand took effect globablly
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\lipsum[1-15]
\mychapter{Hello}
\lipsum[1-15]
\end{document}


But if, for example, I wrote instead

\afterpage{\gdef\myname{someone else'sname}}


Then the desired effect occurred.

So I concluded that the OP's problem stemmed from the fact that

\afterpage{\loadgeometry{mydefaultgeometry}}


only sets the parameters for the page geometry locally, not globally. (I tried the same experiment with the package everyshi; same conclusion.)

# Manually reset values from within \afterpage

So, in order to automatically change the page geometry, I thought I could do something like:

\afterpage{\setlength{\global\oddsidemargin}{1in}%
\setlength{\global\evensidemargin}{1in}%
\setlength{\global\textwidth}{\dimexpr\paperwidth-2in\relax}%
}


But I got completely unexpected results: namely, the changes were inconsistently occurring. Here's MWE:

\documentclass{report}
\usepackage{afterpage}
\usepackage{lipsum}
\usepackage[showframe,margin=1in]{geometry}
%%
\newcommand{\myname}{AEllett}
\newcommand{\mychapter}[1]{%
\newgeometry{margin=3in}
\chapter{#1}%
\afterpage{\setlength{\global\oddsidemargin}{0in}%
\setlength{\global\evensidemargin}{0in}%
\setlength{\global\textwidth}{\dimexpr\paperwidth-2in\relax}%
%%\setlength{\global\linewidth}{\dimexpr\paperwidth-2in\relax}%
}
}
\begin{document}
\lipsum[1-15]
\mychapter{Hello}
\lipsum[1-25]
\end{document}


Something very strange is happening.

# Manually setting all page dimensions

I thought maybe there was some bad interaction between using the geometry package and my manually setting things. So, I tried the experiment again without using the geometry package.

MWE:

\documentclass{report}
\usepackage{afterpage}
\usepackage{lipsum}
\usepackage{showframe}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6in}
%%
\newcommand{\myname}{AEllett}
\newcommand{\mychapter}[1]{%
\setlength{\oddsidemargin}{3in}
\setlength{\evensidemargin}{3in}
\setlength{\textwidth}{3in}
\chapter{#1}%
\afterpage{\setlength{\global\oddsidemargin}{0in}%
\setlength{\global\evensidemargin}{0in}%
\setlength{\global\textwidth}{\dimexpr\paperwidth-2in\relax}%
%%\setlength{\global\linewidth}{\dimexpr\paperwidth-2in\relax}%
}
}
\begin{document}
\lipsum[1-15]
\mychapter{Hello}
\lipsum[1-25]
\end{document}


What I find interesting is that I am successfully able to change the effective left-hand side margin. But, I am not able to change the width of the text. Uncommenting the lines for setting \linewidth doesn't make matters any better.

# Forgetting about doing anything fancy with chapters!

I decided to try to change parameters mid-document and see what happens.

MWE:

\documentclass{report}
\usepackage{afterpage}
\usepackage{lipsum}
\usepackage{showframe}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6in}
%%
\begin{document}
\lipsum[1-15]

\setlength{\global\oddsidemargin}{2in}%
\setlength{\global\evensidemargin}{2in}%
\setlength{\global\textwidth}{\dimexpr\paperwidth-4in\relax}%

\lipsum[1-25]
\end{document}


I get similar results.

I do not understand what is going on here. showframe clearly believes that the dimensions of the text width have been changed. Why doesn't LaTeX?

If I add the following to my preamble:

\usepackage{fancyhdr}
\pagestyle{fancy}


I can see that \textwidth has in fact been changed: and as I understand the conversion between inches and pts, the correct values are being displayed.

# \linewidth won't let me change it!!!

I tried comparing \textwidth to \linewidth. There were discrepencies. So I went in and manually changed \linewidth *to absolutely no avail!!!

MWE:

\documentclass{report}
\usepackage{afterpage}
\usepackage{lipsum}
\usepackage{showframe}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6in}
%%
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\lipsum[1-15]

\setlength{\global\oddsidemargin}{2in}%
\setlength{\global\evensidemargin}{2in}%
\setlength{\global\textwidth}{\dimexpr\paperwidth-4in\relax}%
\setlength{\global\linewidth}{\dimexpr\paperwidth-4in\relax}%
%%\large\normalsize
%%\clearpage

\lipsum[1-25]
\end{document}


How is it possible to apparently have the correct \textwidth and yet not have the correct \textwidth? Why does LaTeX ignore what I'm doing when I'm setting \linewidth?

What am I failing to understand here?

EDIT

I just found \hsize. Setting that seems to work! Sigh! Effects are predictably ugly, but \hsize does make the necessary changes effective.

This edit might suggest that I have a solution. I guess I do. But, I don't really understand what I've done. What other parameters are there that might have be reset? Why did I have to go in and change \hsize, the only documentation I can find for it is in source2e and what I find there seems a bit obfuscatory. :*(

So, I still welcome feedback from others who understand better what I've done.

-

## closed as too broad by David Carlisle, Guido, percusse, Martin Schröder, lockstepJul 6 '13 at 23:52

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

Dear Moderators, what do I do with this question? In the process of writing up my various attempts and ideas about how to solve my problem, I hit upon an idea that solved my dilemma. Do I leave the question? Is it nevertheless valuable for the community? –  A.Ellett Feb 7 '13 at 5:57
A more appropriate (logical) use of \global is \global\setlength{<len>}{<len>}. You can answer things yourself on this site. We're cool like that. The community is the ultimate decider on whether something is valuable or not. But I would encourage you to write up a solution. –  Werner Feb 7 '13 at 6:13
Manually changing \linewidth is something you shouldn't do; it's automatically maintained by LaTeX to reflect the current line width (particularly useful for lists). –  egreg Feb 7 '13 at 7:38
@Werner \global\setlength doesn't work if the calc package is loaded; but \setlength{\global<len>}{<len>} does. :-) –  egreg Feb 7 '13 at 9:07
all your attempts are doomed to failure, since tex (not just latex) “compiles ahead”. so when tex comes to make a page break, it considers the block of text in which the page break is going to fall ... and it knows this because it's already compiled that block of text. furthermore, it has no way of “uncompiling” anything, so the stuff after the split remains at the width of the page that is being committed. which is why your changes of line width appear to have no effect. you have to clear the page to change the line width, though things like latex quote environment can provide some help –  wasteofspace Feb 7 '13 at 10:21