34

Objective

How to change the heading of landscaped pages from

alt text

to

alt text

?

Minimal Code

\documentclass{book}
\usepackage[a5paper,hmargin=3cm,vmargin=5cm]{geometry}
\usepackage{lscape,lipsum}

\begin{document}
\chapter{One}
\lipsum[1]

\section{One One}
\lipsum[2]

\newgeometry{hmargin=5cm,vmargin=3cm}

\begin{landscape}
\lipsum[3-5]
\end{landscape}

\restoregeometry
\lipsum[6]

\end{document}

Edit 1 (my real scenario layout)

In my real scenario, the left-right margins should not be occupied by headings.

alt text

lockstep
  • 250,273
Display Name
  • 46,933

5 Answers5

24

The lscape package is not designed for this. It's designed for rotating wide figures or tables, for example. And the geometry package explicitly says that \newgeometry can't change the paper size or orientation. So I don't think there's a way to do this automatically.

You can include landscape oriented pdf pages using the pdfpages package. (Include them with the [landscape] option.)

A new solution

You could also use the textpos package to place the headers. By combining this with the fancyhdr package, you can pretty much automate it.

\documentclass[twoside]{book}
\usepackage[a5paper,hmargin=3cm,vmargin=5cm]{geometry}
\usepackage{lscape,lipsum,graphicx}
\usepackage[absolute]{textpos}
\usepackage{fancyhdr}

\fancypagestyle{lscape}{% 
\fancyhf{} % clear all header and footer fields 
\fancyfoot[LE]{%
\begin{textblock}{20}(1,5){\rotatebox{90}{\leftmark}}\end{textblock}
\begin{textblock}{1}(13,10.5){\rotatebox{90}{\thepage}}\end{textblock}}
\fancyfoot[LO] {%
\begin{textblock}{1}(13,10.5){\rotatebox{90}{\thepage}}\end{textblock}
\begin{textblock}{20}(1,13.25){\rotatebox{90}{\rightmark}}\end{textblock}}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{0pt}}

\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}

\begin{document}
\chapter{A chapter}
\section{A section}
\lipsum
\section{A section}
\lipsum

\newgeometry{hmargin=3cm,vmargin=5cm}
\thispagestyle{lscape}
\pagestyle{lscape}
\begin{landscape}
\lipsum[1-3]

\end{landscape}

\restoregeometry
\pagestyle{headings}
\lipsum[6]

\end{document}
Alan Munn
  • 218,180
  • @Alan: Thanks for answering. Unfortunately, my scenario does not match your suggestion. There is no pdf page to be imported. And I don't want to create such pdf because it is tedious job. – Display Name Jan 16 '11 at 14:54
  • @xport I added a different solution. Maybe that will work for you. – Alan Munn Jan 16 '11 at 17:50
  • @Alan: This should work. The code seems to be pasted twice. Furthermore, \thispagestyle{lscape} is enough, \pagestyle{lscape} may be deleted. (and \newgeometry may be deleted?) – Leo Liu Jan 16 '11 at 17:57
  • @Leo Thanks for catching the duplicate code. No, I don't think the \pagestyle command can be removed, since we need any subsequent landscape pages to be that pagestyle too. The \newgeometry command was in xport's original example; it's needed so that the landscape pages have the right size. – Alan Munn Jan 16 '11 at 18:31
  • @Alan: heading and page number should be at top right and bottom center, respectively. Your settings does not match a bit. – Display Name Jan 16 '11 at 22:50
  • @xport Examples are just that. Proof of solution. I'm sure you can figure out how to get the pieces in the right place. – Alan Munn Jan 17 '11 at 00:23
  • @xport But since you asked, I've updated the code to your specs. Since you don't say whether your document is one or two sided, I've left in the two sided version, which may be helpful to others. – Alan Munn Jan 17 '11 at 00:57
  • @Alan: thanks for the solution. However, how do you get the values of 13, 10.5, 13.25? They make exact positions or approximation you got by trial and errors? – Display Name Jan 17 '11 at 01:07
  • @xport I did them by trial and error, but you could calculate them based on the various pagesize lengths. – Alan Munn Jan 17 '11 at 01:11
16

I need page numbers on the landscaped pages. And the page numbers should be at the bottom as shown in the second figure above.

I have an idea. We can use \fancypagestyle to define a new pagestyle with landscaped page numbers. I use tikz to put the page number.

\fancypagestyle{lscapedplain}{%
  \fancyhf{}
  \fancyfoot{%
    \tikz[remember picture,overlay]
      \node[outer sep=1cm,above,rotate=90] at (current page.east) {\thepage};}
}

This would also be done by \newpagestyle from titlesec.

Leo Liu
  • 77,365
  • I accidentally undid my vote on your answer. If you edit your answer, I can upvote it again. :-) – Alan Munn Jan 16 '11 at 18:32
  • @Alan: I think the code here shows the key to the question. (So does yours.) @xport can do the rest herself. Never mind about voting. – Leo Liu Jan 17 '11 at 04:56
  • Leo: I came back to this question to solve a problem that a student discovered with my thesis class, so now I've finally got around to voting for this question again. I'm actually going to include it into my thesis class; it's a very nice solution. Thanks. – Alan Munn Aug 25 '11 at 00:05
  • 2
    This solution worked for me, but I had to add the \usepackage{tikz} to my document preamble. It also added a vertical line on the right side of my landscape-d page, which I had to get rid of using: \renewcommand{\headrulewidth}{0pt} – John Mark Jan 07 '15 at 16:23
  • Nice lightweight solution! Can the size of the number be changed somehow? – Christian Nov 27 '19 at 17:18
8

Analternative approach using package typearea to switch to landscape-mode mid-document. Though it is really strange to do that.

exportNewGeometry

\documentclass[usegeometry,paper=a5,pagesize,headinclude]{book}
\usepackage{typearea}
\usepackage{lipsum}

\begin{document}
\chapter{One}
\lipsum[1]

\section{One One}
\lipsum[2]

\storeareas\normalsetting
\KOMAoption{paper}{landscape}
\areaset{2\textwidth}{.9\textheight}
\recalctypearea
    \lipsum[3-5]
\clearpage
\normalsetting
\lipsum[6]

\end{document}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
8

This method is answered by @Leo Liu, from http://bbs.ctex.org/forum.php?mod=viewthread&tid=78285.

Limited by the geometry package itself:

Unlike \geometry in the preamble,\newgeometry is available only after \begin{document}, resets all the options ever specified except for the papersize-related options: landscape, portrait, and paper size options (such as papersize, paper=a4paper and so forth), which can’t be changed with \newgeometry.

-- Geometry package manual

Make a patch so that the \newgeometry command uses the landscape and portrait options.

\usepackage{etoolbox}

\makeatletter
\def\ifGm@preamble#1{\@firstofone}
\appto\restoregeometry{%
  \pdfpagewidth=\paperwidth
  \pdfpageheight=\paperheight}
\apptocmd\newgeometry{%
  \pdfpagewidth=\paperwidth
  \pdfpageheight=\paperheight}{}{}
\makeatother

Complete example:

\documentclass{book}
\usepackage[a5paper,hmargin=3cm,vmargin=5cm]{geometry}
\usepackage{lscape,lipsum}
\usepackage{etoolbox}

\makeatletter
\def\ifGm@preamble#1{\@firstofone}
\appto\restoregeometry{%
  \pdfpagewidth=\paperwidth
  \pdfpageheight=\paperheight}
\apptocmd\newgeometry{%
  \pdfpagewidth=\paperwidth
  \pdfpageheight=\paperheight}{}{}
\makeatother

\begin{document}
\chapter{One}
\lipsum[1]

\section{One One}
\lipsum[2]

\newgeometry{,hmargin=3cm,vmargin=5cm,landscape}

\lipsum[3-5]

\restoregeometry
\lipsum[6]

\end{document}

enter image description here

沙漠之子
  • 489
  • 4
  • 7
5

Here is a suggestion using scrlayer to define a new pagestyle for these rotated pages.

\documentclass{book}
\usepackage[a5paper,hmargin=3cm,vmargin=5cm]{geometry}
\usepackage{lscape,lipsum}

\usepackage{scrlayer}
\DeclareNewLayer[
  background,
  rightmargin,
  contents={%
    \parbox[b][\layerheight][c]{\dimexpr\footskip+\footheight\relax}{%
      \hfill\rotatebox{90}{\pagemark}}}
]{lscape.foot}
\DeclareNewLayer[
  background,
  textarea,
  addhoffset=\dimexpr-\headsep-\headheight\relax,
  width=\dimexpr\headsep+\headheight\relax,
  contents={\hfill\rotatebox{90}{\headmark}\hspace*{\headsep}}
]{lscape.head}
\DeclareNewPageStyleByLayers{lscape}{lscape.foot,lscape.head}

\begin{document}
\chapter{One}
\lipsum[1]
\section{One One}
\lipsum[2]

\newgeometry{hmargin=5cm,vmargin=3cm}
\begin{landscape}
\pagestyle{lscape}
\lipsum[3-10]
\end{landscape}

\restoregeometry
\lipsum[6]
\end{document}

enter image description here

esdd
  • 85,675