I am hoping that a TeX expert can provide a solution to the issues
illustrated in the following minimal example code.
The issue in question is that \begin{landscape} ... \end{landscape} has
effects that propagate outside the landscape environment. This can
result in previously made changes to \textheight and other lengths not
being properly restored after the change back to portrait mode.
A solution/ work-around is to issue a subsequent
\changepage{100mm}{40mm}{-20mm}{-20mm}{}{}{}{-50mm}{-50mm}%
at an appropriate level of nesting to reverse previous changes.
This may also require that the original \changepage is issued at the
outermost level of nesting.
However, these do not seem to be particular elegant solutions.
The code in lscape.sty seems relatively small and may be simple to
modify by someone that understands low-level TeX better than I do!
(Unfortunately, my knowledge is limited to LaTeX usage.)
There is also the alternative \begin{LandScape} ... \end{LandScape}
environment defined as part of the fancybox package. This also has
issues (different ones from landscape) that make it less than
completely satisfactory. In particular, using LandScape, the
left-right position of the footer is incorrect after the return to
portrait format. LandScape messes with \textwidth which fancyhdr uses
as the basis of it's definition of \headwidth. Note that landscape
doesn't change \textwidth which has the benefit of avoiding
complications with the width of the footer.
In general, I shall have many pages within the landscape format (for
example, a lengthy longtable). Consequently, I have no current
interest in other methods for rotating text that allow only a single
page in landscape format (float-related methods).
Here is the minimal example that I have prepared relating to landscape:
\documentclass[a4paper, 12pt, dvips]{article}%
\usepackage[dvips]{graphicx, color, lscape}%
\usepackage{chngpage}%
\usepackage{fancyhdr}%
\renewcommand{\headrulewidth}{0pt}%
\lfoot{Left}%
\cfoot{\thepage}%
\rfoot{Right}%
\pagestyle{fancy}%
\newcommand{\showlinelengths}{%
textheight:\par
\rule{\textheight}{2mm}\par
textwidth:\par
\rule{\textwidth}{2mm}\par
linewidth:\par
\rule{\linewidth}{2mm}\par
headwidth:\par
\rule{\headwidth}{2mm}\par% (a length defined by fancyhdr package)
}%
\begin{document}%
{%
%Set up parameters here.
%No need to subsequently restore to original values since within a
group defined by the above {
%e.g.,
\setlength{\parindent}{0pt}%
%etc.
This page is in portrait format.\par
\showlinelengths%
%Make text area shorter by 100mm and narrower by 40mm (from perspective
of portrait format).
%The 20mm margin change is used so that the 40mm width change is
applied equally to the left and right.
%By increasing \headsep and \footskip by 50mm, the 100mm change is
shared equally between the top and bottom and the vertical position of
the footer remains unchanged.
%[Actually, there is a small change in footer vertical position between
page 1 and 2 which also needs to be investigated!]
\clearpage%
\changepage{-100mm}{-40mm}{20mm}{20mm}{}{}{}{50mm}{50mm}%
%It is also desired that the horizontal position of the footer remains
unchanged.
%The following achieves this objective by having the footer extend 20mm
into the margins at the L and R to counteract the margin change.
\fancyhfoffset[L]{20mm}%
\fancyhfoffset[R]{20mm}%
This page is also in portrait format.\par
\showlinelengths%
\clearpage%
%From the perspective of landscape format, the above \changepage has
the effect of making width of text area narrower by 100mm and height
less by 40mm.
\begin{landscape}%
This page is in landscape format.\par
\showlinelengths%
\end{landscape}%
This page is in portrait format.\par
\showlinelengths%
The problem is that none of textheight, textwidth or linewidth have
reverted to their original settings.\par
The textheight line measures as 109mm (which is the same as for the
portrait page value after the changepage reducing textheight by 50mm)
whereas in the landscape page it measures as 97mm (being the portrait
textwidth value after the changepage command which landscape has
appropriately used in landscape mode for the landscape height).\par
Both these values are much less than the original value of textheight
shown in the first portrait page.\par
The left/ right positioning of the footer is okay.\par
%\begin{landscape} .... \end{landscape} has done more than just
typeset the enclosed text in landscape mode! It has the unfortunate
side-effect of propagating the changes it makes such that they remain
in effect after the landscape environment.\par
%Looking at the code in lscape.sty, it seems that this is as a result
of
%\global\@colht=\textheight
%\global\vsize=\textheight
%\global\@colroom=\textheight}
%which result in the landscape changes propagating up to higher levels,
thereby over-writing settings that may have been defined at lower
levels of nesting (as by \changepage in the presented example).
%Is is possibly to modify the code in lscape.sty to avoid such
side-effects?
}%(end of group)
The vertical position of the footer seems rather unpredictable at this
stage. With little text after the end of the landscape environment,
it is too high on the single portrait page. However, with more text,
resulting in a page break, the footer vertical positioning problem may
either be apparent on (i.e., transfer to) a subsequent page or may sort
itself out as it seems to do in this example.
\end{document}%
Many thanks for any help,
Douglas
Hello again,
Further to my original posting (which for some reason seems to have
been unfortunately duplicated - please accept my apologies), I can add
the following additional comments/ symptoms.
After the \end{landscape}, it is only the first of the subsequent pages
generated in portrait format that exhibit the problem (i.e., of narrow
width, short height and footer much too high up the page). If a lot of
text is added, it will be seen that subsequent pages in the portrait
format have all the correct attributes. So something just needs to be
added (ideally to lscape.sty) to trigger reuse of the original
parameters immediately after the return to portrait format.
This is to be contrasted with behaviour of the same example but using
LandScape instead of landscape environment.
This involves addition of \usepackage{fancybox} and the following
instead of the \begin{landscape} ... \end{landscape}.
\begin{LandScape}{\rotatebox{90}}%
This page is in landscape format.\par
\showlinelengths%
\end{LandScape}%
Enter lots of text here ...
With the LandScape environment and a lot of text in the final portrait
format part, again immediately after the return to portrait format
everything is incorrect (i.e., narrow width, short height and footer
much too high up the page). On subsequent pages of the final portrait
part, the width remains too narrow on all pages although the height and
footer vertical position seem to sort themselves out after the first of
the portrait pages. The left/ right position of the footer does not
seem to be a problem (at least for this example) although I had
previously found this aspect to be also problematic in other work
involving use of the LandScape environment.
Douglas
Could you possibly repost it with comments removed?
Because of line wrapping that has occured in transmission,
it is impossible to tell where a comment ends (sometimes
even where it begins).
>
> Here is the minimal example that I have prepared relating to landscape:
[...]
> %No need to subsequently restore to original values since within a
> group defined by the above {
The above linebreak seems to be unintended, but others
are not so obvious.
One should either ensure that code is unaffected by line
breaks or use only short lines.
Dan
Okay, I have shortened all lines that are comments. If a line starts
with a % it is a comment.
The text lines that remain which do not start with a % represent text
that is considered helpful to illustrate the effect.
I wrote the text (which can be considered as example document content)
in the form of a running commentary. I had commented out some of these
content lines since they contained references to LaTeX commands but now
realise that this may be a little confusing. (Perhaps I should have
used verbatim or similar.)
I am now providing two versions (refer below):
A) As described above with remaining content text lines and short
comment lines.
B) With no text content.
I have changed the example slightly by adding an extra portrait page at
the end (page 5). This is generated after the end of the group
defined by { ... }. It is now only on the last page that the problem
is seen - i.e., the footer is too high on page 5.
As I write this, I am noticing some interesting effects ...
If I comment out the 3 lines as follows:
%\begin{landscape}%
%\showlinelengths%
%\end{landscape}%
then, as expected one less page is generated.
The problem remains on the last page (which is now, of course, page 4).
Since landscape is no longer involved it seems that my original
thinking that landscape was to blame is flawed!
It will be observed that the line lengths are shown the same on pages 1
and 4 (i.e., the page numbered 4 after the 3 lines are commented out),
yet the footer position is different on pages 1 and 4. \textheight
does not seem to be actioned properly.
I read somewhere that a change in \textheight is applied to the
following page rather than the current page were it is changed. It is
probably something like this that is causing the trouble.
The question remains as to why the effects of \changepage are not
contained within the { .... } grouping.
What can I change so that the current value of \textheight is
immediately applied?
Douglas
Here is the example again:
A)
\documentclass[a4paper, 12pt, dvips]{article}%
\usepackage[dvips]{graphicx, color, lscape}%
\usepackage{chngpage}%
\usepackage{fancyhdr}%
\renewcommand{\headrulewidth}{0pt}%
\lfoot{Left}%
\cfoot{\thepage}%
\rfoot{Right}%
\pagestyle{fancy}%
\newcommand{\showlinelengths}{%
textheight:\par
\rule{\textheight}{2mm}\par
textwidth:\par
\rule{\textwidth}{2mm}\par
linewidth:\par
\rule{\linewidth}{2mm}\par
headwidth:\par
\rule{\headwidth}{2mm}\par% (a length defined by fancyhdr package)
}%
\begin{document}%
{%
%Set up parameters here.
%No need to subsequently restore to original values since
%within a group defined by the above {
%e.g.,
\setlength{\parindent}{0pt}%
%etc.
This page is in portrait format.\par
\showlinelengths%
%Make text area shorter by 100mm and narrower
%by 40mm (from perspective of portrait format).
%The 20mm margin change is used so that the 40mm
%width change is applied equally to the left and right.
%By increasing \headsep and \footskip by 50mm,
%the 100mm change is shared equally between
%the top and bottom and the vertical position
%of the footer remains unchanged.
%[Actually, there is a small change in footer
%vertical position between page 1 and 2 which
%also needs to be investigated!]
\clearpage%
\changepage{-100mm}{-40mm}{20mm}{20mm}{}{}{}{50mm}{50mm}%
%It is also desired that the horizontal position of the
%footer remains unchanged.
%The following achieves this objective by having the
%footer extend 20mm into the margins at the L and R
%to counteract the margin change.
\fancyhfoffset[L]{20mm}%
\fancyhfoffset[R]{20mm}%
This page is also in portrait format.\par
\showlinelengths%
\clearpage%
%From the perspective of landscape format,
%the above \changepage has the effect of making width
%of text area narrower by 100mm and height less by 40mm.
\begin{landscape}%
This page is in landscape format.\par
\showlinelengths%
\end{landscape}%
This page is in portrait format.\par
\showlinelengths%
The problem is that none of textheight, textwidth or linewidth have
reverted to their original settings.\par
The textheight line measures as 109mm (which is the same as for the
portrait page value after the changepage reducing textheight by 50mm)
whereas in the landscape page it measures as 97mm (being the portrait
textwidth value after the changepage command which landscape has
appropriately used in landscape mode for the landscape height).\par
Both these values are much less than the original value of textheight
shown in the first portrait page.\par
The left/ right positioning of the footer is okay.\par
%comment lines: \begin{landscape} .... \end{landscape} has done more
%than just typeset the enclosed text in landscape mode!
%It has the unfortunate side-effect of propagating the
%changes it makes such that they remain in effect after
%the landscape environment.
%Looking at the code in lscape.sty, it seems that this is as a result
of
%comment line: \global\@colht=\textheight
%comment line: \global\vsize=\textheight
%comment line: \global\@colroom=\textheight}
%which result in the landscape changes propagating up
%to higher levels, thereby over-writing settings
%that may have been defined at lower levels of nesting
%(as by \changepage in the presented example).
%Is is possibly to modify the code in lscape.sty to
%avoid such side-effects?
\clearpage%
}%(end of group)
\showlinelengths%
The vertical position of the footer seems rather unpredictable at this
stage. With little text after the end of the landscape environment,
it is too high on the single portrait page. However, with more text,
resulting in a page break, the footer vertical positioning problem may
either be apparent on (i.e., transfer to) a subsequent page or may sort
itself out as it seems to do in this example.
\clearpage%
\end{document}%
B) The same but with no comments or text content apart from labelling
of rules illustrating the lengths:
\documentclass[a4paper, 12pt, dvips]{article}%
\usepackage[dvips]{graphicx, color, lscape}%
\usepackage{chngpage}%
\usepackage{fancyhdr}%
\renewcommand{\headrulewidth}{0pt}%
\lfoot{Left}%
\cfoot{\thepage}%
\rfoot{Right}%
\pagestyle{fancy}%
\newcommand{\showlinelengths}{%
textheight:\par
\rule{\textheight}{2mm}\par
textwidth:\par
\rule{\textwidth}{2mm}\par
linewidth:\par
\rule{\linewidth}{2mm}\par
headwidth:\par
\rule{\headwidth}{2mm}\par% (a length defined by fancyhdr package)
}%
\begin{document}%
{%
\setlength{\parindent}{0pt}%
\showlinelengths%Page 1
\clearpage%
\changepage{-100mm}{-40mm}{20mm}{20mm}{}{}{}{50mm}{50mm}%
\fancyhfoffset[L]{20mm}%
\fancyhfoffset[R]{20mm}%
\showlinelengths%Page 2
\clearpage%
\begin{landscape}%
\showlinelengths%
\end{landscape}%
\showlinelengths%
\clearpage%
}%
\showlinelengths%
\clearpage%
\end{document}%
As a further test of the behaviour, I added generation of another page
using
\showlinelengths%
\clearpage%
These lines were added just before the \end{document} - i.e., outside
the group defined by { ... }
The problem (of the footer being too high) now occurs on the second
from last page (landscape is no longer on trial!)
So, answering part of my own question:
"Why are the effects of \changepage not contained within the { .... }
grouping. "
The answer seems to be that the changes are properly contained within
the grouping.
The first and last pages are the same (apart from the parindents that
are occuring as would be expected on the last page) which clearly
demonstrates this.
The remaining question/ problem is:
What can I change so that the current value of \textheight is
immediately applied rather than on a subsequent page?
I have included below the code with the extra page generation added for
the avoidance of doubt as to what I am talking about!
Douglas
\showlinelengths%Page 3
\end{landscape}%
\showlinelengths%Page 4
\clearpage%
}%
\showlinelengths%Page 5 (Problem of high footer!)
\clearpage%
\showlinelengths%Page 6
\clearpage%
\end{document}%
> I read somewhere that a change in \textheight is applied to the
> following page rather than the current page were it is changed. It is
> probably something like this that is causing the trouble.
>
> The question remains as to why the effects of \changepage are not
> contained within the { .... } grouping.
>
> What can I change so that the current value of \textheight is
> immediately applied?
I hadn't the time to look into your example. But some remarks: If you
change textheight the length register adapts immediatly but only the
next page will have the changed layout. So your \showlinelength command
isn't really reliable. If you want to change the textbody of the
current page you can use \enlargethispage (but it will not affect the
header/footer placement). Changing the page layout isn't easy. You
should perhaps consider if there isn't a better way to achieve what you
want.
\documentclass{article}
\begin{document}
text1 \hfill text2
\vfill
\setlength\textheight{1cm}%
\rule{\textheight}{1pt}
text3 \hfill text4
\newpage
text1 \hfill text2
\vfill
\rule{\textheight}{1pt}
text3 \hfill text4
\end{document}
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Yes, it is now clear that \textheight is properly restored immediately
after the end of the group defined by the closing brace ...}
However, as your and my examples demonstrate, \textheight is only
applied to the next page.
In my example, I am not trying to change \textheight in the middle of a
page. After the end of the group nothing has been typeset on the page
so TeX should really use the current value when subsequently
typesetting that page. Is there any way to persuade TeX to do so? I
tried adding \clearpage after the end of the group
i.e.,
...}%
\clearpage%(addition)
\showlinelengths%Page 5 (Problem of high footer!)
\clearpage%
\showlinelengths%Page 6
\clearpage%
\end{document}%
However, this does not solve the problem. Any other ideas?
No doubt there are other ways of achieving a practical result but my
code will become more complicated and less elegant. I am generating
tables from a database with a programming language creating the LaTeX.
The structure is as follows:
\begin{document}%
{%
%Set up parameters ...
%Based on text to be typeset, specify portrait or landscape
%and appropriate margins whilst keeping footer position
%and footer width unchanged.
%e.g., (for particular margins and landscape format)
\clearpage%
\changepage{-100mm}{-40mm}{20mm}{20mm}{}{}{}{50mm}{50mm}%
\fancyhfoffset[L]{20mm}%
\fancyhfoffset[R]{20mm}%
\clearpage%
\begin{landscape}%
%Typeset the material for one or more pages (usually longtable)
\end{landscape}%
\clearpage%
}%
%Revert automatically to default (known) original settings,
%default page format and margins.
%Do something similar - repeat above process ...
%Different format, margins,
%...
\end{document}%
(The \clearpage statements in the above are probably not doing anything
and can be omitted. This is on the understanding that no output is
generated except where shown as "Typeset the material ...")
I reiterate that I am not trying to change setting within a page. I do
not need to do this for my application.
Douglas
the old value needs to be restored before the final \clearpage: tex
calculates the values at page ship out time (i.e., when \clearpage
happens on a non-empty page).
>Is there any way to persuade TeX to do so? I
>tried adding \clearpage after the end of the group
if there's one inside the group, the one after the group will have no
effect.
--
Robin Fairbairns, Cambridge
This achieves a result, although the code has lost it's inherent
elegance.
It is a pity that there does not seem to be a simple hack whereby
something at low level can be redefined. It seems rather like a design
flaw in TeX or LaTeX that it does not use the current value of
\textheight present at the beginning of a page before anything has been
generated. Other values such as \textwidth are properly immediately
used, so why not also the height?!
Douglas
Code now as follows:
\begin{document}%
{%
\setlength{\parindent}{0pt}%
\showlinelengths%Page 1
\clearpage%
\changepage{-100mm}{-40mm}{20mm}{20mm}{}{}{}{50mm}{50mm}%
\fancyhfoffset[L]{20mm}%
\fancyhfoffset[R]{20mm}%
\showlinelengths%Page 2
\clearpage%
\begin{landscape}%
\showlinelengths%Page 3
\end{landscape}%
\showlinelengths%Page 4
\addtolength{\textheight}{100mm}%This corrects footer on page 5
\clearpage%
%\addtolength{\textheight}{100mm}%No effect if here!
}%
\showlinelengths%Page 5 (Was problem with footer. Now seems okay.)
> Following Robin's words of wisdom, I added an
> \addtolength{\textheight}{100mm} before
> the end of page 4 (which is within the group). This has to be done
> before the \clearpage of page 4.
>
> This achieves a result, although the code has lost it's inherent
> elegance.
It isn't the correct result anyway, because the text height is wrong while
the preceding pages are output.
The *real* way to change page layout on the fly is to apply the
parameters using \onecolumn. (The chngpg package is a poor fake.)
http://groups.google.com/group/comp.text.tex/msg/0ccfdacf3ab808b1
--
Donald Arseneau as...@triumf.ca