[Tex/LaTex] Change page orientation inside document

fancyhdrheader-footerlandscape

I need to create a document with a title page, some introduction pages and a lot of tables. Those tables needs to be on landscape pages. So I need to switch the orientation on a certain page.

Also the borders should be very narrow, because I need a lot of space for the tables and documentation.

I found several solutions but non of them are working really good. Also the fancy header should continue on the landscape pages but should get the width of the page.

Here come one example:

\documentclass[a4paper,headsepline,footsepline]{report}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage[pdftex]{color}

\usepackage{typearea}
\usepackage{fancyhdr}

\usepackage{ngerman}

\usepackage{hyperref}
\setlength{\voffset}{-0.9in}
\setlength{\hoffset}{-0.9in}
\setlength{\textheight}{9.5in}
\setlength{\textwidth}{7in}
\setlength{\marginparwidth}{1in}

\pagestyle{fancy}
\fancyhf{}
\rhead{LOGO}
\lhead{CargoSoft Dokumentation}
\rfoot{Page \thepage}

\definecolor{cargosoft}{RGB}{1,107,181}

\newcommand{\myRule}[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\begin{document}

\begin{titlepage}
    \centering
    LOGO
    {\scshape\LARGE Company name \par}
    \vspace{1.5cm}
    \myRule[cargosoft]{8cm}{0.4pt} \par
    \vspace{0.5cm}
    {\huge\bfseries document name\par}
    \vspace{0.5cm}
    \myRule[cargosoft]{8cm}{0.4pt} \par
    \vspace{2cm}

    \vfill

    {\large \today\par}
\end{titlepage}

First page content comes here not in landscape

\KOMAoption{paper}{landscape}
\pagestyle{fancy}
\fancyhf{}
\rhead{LOGO}
\lhead{Dokumentation Landscape pages}
\rfoot{Page \thepage}

\areaset{\textwidth}{\textheight}
\recalctypearea
content on landscape pages
\end{document}

The next thing I tried comes from this post How to switch from portrait to landscape page orientation? The result is, that the page is in landscape, but the fancy header is not. Also the content is horizontal centered.

\documentclass[a4paper,headsepline,footsepline]{report}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage[pdftex]{color}
\usepackage[margin=0.5cm]{geometry}

\usepackage{typearea}
\usepackage{fancyhdr}

\usepackage{ngerman}

\usepackage{hyperref}

\usepackage{pdflscape}


\pagestyle{fancy}
\fancyhf{}
\rhead{LOGO}
\lhead{CargoSoft Dokumentation}
\rfoot{Page \thepage}

\definecolor{cargosoft}{RGB}{1,107,181}

\newcommand{\myRule}[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\begin{document}

\begin{titlepage}
    \centering
    LOGO
    {\scshape\LARGE Company name \par}
    \vspace{1.5cm}
    \myRule[cargosoft]{8cm}{0.4pt} \par
    \vspace{0.5cm}
    {\huge\bfseries document name\par}
    \vspace{0.5cm}
    \myRule[cargosoft]{8cm}{0.4pt} \par
    \vspace{2cm}

    \vfill

    {\large \today\par}
\end{titlepage}

First page content comes here not in landscape
\begin{landscape}
content on landscape pages
\end{landscape}
\end{document}

Second try with \begin{landscape} and package pdflscape

Does anyone has a good working solution for me?

Thanks a lot,
Hauke

Best Answer

Here is a solution with typearea:

You can use the optional paramerter DIV=<value> to control the space for the text area.

For the header/footer a new pagestyle needs to be defined. It has to contain \headwidth=\textwidth to set the correct width for the landscape pages.

Before switching to landscape, a new page must be started. Without it, the new settings may affect the previous page.

And in order to make the viewer show the pages in landscape, \pdfpageheight and \pdfpagewidht must be set.

\documentclass[a4paper,headsepline,footsepline]{report}
\usepackage[utf8]{inputenc}
\usepackage[pdftex]{graphicx}
\usepackage[pdftex]{color}

% uses DIV=8
\usepackage{typearea}
% set DIV to squeeze out more space for text area 
%\usepackage[DIV=12]{typearea}
\usepackage{fancyhdr}

\usepackage{ngerman}

\usepackage{hyperref}

\pagestyle{fancy}
\fancyhf{}
\rhead{LOGO}
\lhead{CargoSoft Dokumentation}
\rfoot{Page \thepage}

% new pagestyle
\fancypagestyle{lscape}{%
  % important, sets the width of head and foot to current textwidth
  \headwidth\textwidth
  % not needed as long as header/footer parts don't change
  %\fancyhf{}
  %\rhead{LOGO}
  %\lhead{CargoSoft Dokumentation}
  %\rfoot{Page \thepage}
}

\definecolor{cargosoft}{RGB}{1,107,181}

\newcommand{\myRule}[3][black]{\textcolor{#1}{\rule{#2}{#3}}}

\begin{document}

\begin{titlepage}
    \centering
    LOGO
    {\scshape\LARGE Company name \par}
    \vspace{1.5cm}
    \myRule[cargosoft]{8cm}{0.4pt} \par
    \vspace{0.5cm}
    {\huge\bfseries document name\par}
    \vspace{0.5cm}
    \myRule[cargosoft]{8cm}{0.4pt} \par
    \vspace{2cm}

    \vfill

    {\large \today\par}
\end{titlepage}

First page content comes here not in landscape

% start new page before setting page layout,
% otherwise previous page is also affected
\newpage
\KOMAoption{paper}{landscape}%
\typearea{12}% sets new DIV
\recalctypearea
% needed to show page in landscape in viewer
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth
\pagestyle{lscape}%

content on landscape pages
\end{document}

typearea doesn't give you complete control over the margins. It set the page layout according to rules about the ratio of margins. If you need more control, geometry can be used. But it doesn't support switching to landscape mid document. However, there is a solution for this here. It's downside is, that it may stop working after an update of geometry.

Remark: in your first example you used the typearea package and then set up some lengths for the page layout manually, and in you second example you loaded first geometry and then typearea. Both is not a good idea. In the second case typearea overwrites all settings done with geometry.