0

There is a portrait document in which only the second page have to be made landscape (the document has header and footer made with fancyhdr). To accomplish the portrait to landscape turn I'm using the following:

\pdfpageheight=\paperwidth
\pdfpagewidth=\paperheight
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight 

Also, I'm using geometry to adjust layout in both modes (portrait and landscape). I'm going fine in maintaining the top and left margins across the modes. But I'm not seeing how to manage right and bottom.

To exemplify: I've tried \geometry{bottom=5cm} but in the landscape mode the footer goes beyond the page. It seems that the 4 lines of code above just cut the paper accordingly but foot stays in the same position (as in portrait mode).

What's the proper way to switch from portrait to landscape maintaining margins?

The following demonstrates what happens, foot disappear in landscape.

\documentclass[10pt,a4paper]{article}
\usepackage[left=3cm, top=5cm, headheight=2cm, height=20cm]{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}

\renewcommand{\footrulewidth}{0.4pt}

\begin{document}

\thispagestyle{fancy}
\pagestyle{fancy}

\lipsum[1]

\newpage

\pdfpageheight=\paperwidth
\pdfpagewidth=\paperheight
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight 

\newgeometry{left=3cm, top=5cm, headheight=2cm}

\fancyhfoffset[L]{0pt}

\lipsum[1]

\restoregeometry

\paperwidth=\pdfpageheight
\paperheight=\pdfpagewidth
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth

\lipsum[1]

\end{document}
oqrxke
  • 155
  • Hi, you are right, this pretty much just cuts the page. You are most likely looking for \newgeometry and \restoregeometry. – Johannes_B Jun 27 '15 at 20:20
  • Yes, I'm already doing \newgeometry just after the 4 lines of code shown earlier and then \restoregeometry at the end of the page. The issue is that I'm missing the criteria to maintain the foot at the same (relative to bottom) position in landscape. – oqrxke Jun 27 '15 at 20:25
  • I've read a little bit about koma-script, should it make this easier to deal with? – oqrxke Jun 27 '15 at 20:29
  • Not sure what exactly you are after, maybe the following contains something usefule How to translate and rotate the heading of landscaped pages?; btw: with newgeometry, you should not use the pdf-primitives. geometry will take care of setting everything right. – Johannes_B Jun 27 '15 at 20:35
  • \pdflscale rotates header and footer (they appear horizontally in landscape). – oqrxke Jun 27 '15 at 20:52
  • The landscape environment, provided by the lscape package, rotates the contents of the page before the output routine does its job of adding the header and the footer. (The pdflscape package merely adds appropriate instructions for the previewer to also turn the relevant pages on the screen, so that you don’t have to turn your head instead.) Thus, the header and the footer are kept in their usual position, along the shorter edges of the paper. What’s wrong with this? – GuM Jun 27 '15 at 22:21
  • Now you've clarified the question, this looks like a duplicate of the one @Johannes_B posted. Do you agree? – cfr Jun 28 '15 at 00:46
  • answer to related question https://tex.stackexchange.com/questions/226324/keeping-header-on-top-in-landscape-mode/226414#226414 and here https://tex.stackexchange.com/questions/233336/how-to-adjust-textwidth-and-textheight-to-paper-size-in-mid-document-and-heade/233462#233462 – touhami Jun 28 '15 at 06:04
  • if you use koma-script https://tex.stackexchange.com/questions/228118/setting-custom-paper-size-with-koma-script-pdflatex/228122#228122 – touhami Jun 28 '15 at 06:17
  • @cfr, Yes. And taking the opportunity provided by Alan Munn Jan 17 '11 at 1:11 ("calculate them based on the various pagesize"), I'm concluding the following: \geometry{left=3cm, width=15cm, top=5cm, height=20.7cm} and \newgeometry{left=3cm, width=23.7cm, top=5cm, height=12cm}. I've calculated width and height for each mode considering the a4paper, which is 210 × 297. In other words, manual approach! Why not to have a command to do this magic? Something like \Iwantthesamemargins :) – oqrxke Jun 29 '15 at 01:29
  • @oqrxke OK. Good. That's what I thought. As to the command: sure, if you expect to use this often, it would certainly be worthwhile writing a command to automate it for you. As with most of these things, if you just need it once or twice in a single document, it won't be worth the trouble, but if you need it often in many documents, it will make sense to spend the time on it. – cfr Jun 29 '15 at 01:40
  • May I write such a command? How? – oqrxke Jun 29 '15 at 11:59

1 Answers1

2

If you use pdflscape then, in a landscape environment, the headers and footers remain untouched. Only the content of the page uses the new orientation, and, if your PDF viewer respects the instruction, the relevant page will be automatically rotated for your viewing pleasure.

For example:

\documentclass{article}
\usepackage{pdflscape,kantlipsum}
\pagestyle{headings}
\begin{document}

  \title{Title}
  \author{Author}
  \section{A section}
  \kant[1]
  \begin{landscape}
    \kant[2]
  \end{landscape}
  \kant[3]

\end{document}

pdflscape

If you use lscape, then the page is treated in the same way as with pdflscape but the viewer is not asked to automatically rotate pages.

\documentclass{article}
\usepackage{pdflscape,kantlipsum}
\pagestyle{headings}
\begin{document}

  \title{Title}
  \author{Author}
  \section{A section}
  \kant[1]
  \begin{landscape}
    \kant[2]
  \end{landscape}
  \kant[3]

\end{document}

lscape

In neither case are the headers or footers rotated or the margins of the pages altered for landscaped pages.

cfr
  • 198,882
  • Trying to clarify... I need header and footer aligned with the contents in landscape also. The behavior of of \pdflscape and \lscape isn't desired. – oqrxke Jun 27 '15 at 23:35
  • Just edited the question, updated the sample code which shows the thing: The landscape page is missing the foot (it is beyond the page). I guess height should be added in the \newgeometry{left=3cm, top=5cm, headheight=2cm, height=Xcm} to make it appear. Question is: How to compute X so that distance of the foot from the bottom is the same as in normal (portrait) pages? – oqrxke Jun 27 '15 at 23:55