3

When using pdflscape and fancyhdr, the headers also get rotated. Whilst it's a normal behaviour in most cases (especially when the document has to be printed), I am dealing with a report which will never be printed, so this default behaviour is more annoying.

Here is a MWE of a document dealing with portrait and landscape pages:

\documentclass[a4paper, 10pt]{article}
\usepackage{graphicx}
\usepackage{pdflscape}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[left=2cm, right=2cm, bottom=2cm, top=2cm]{geometry}
\setlength{\headheight}{32pt}

\lhead{\includegraphics[scale=.5]{tt}\\Foo}
\rhead{\includegraphics[scale=.5]{tt}\\\thepage}
\cfoot{}

\fancypagestyle{customlandscape}{%
\fancyhf{}
\newgeometry{left=1cm, right=1cm, bottom=1cm, top=1cm}
% ??
}

\pagestyle{fancy}
\begin{document}

\lipsum[1-10]
\newpage

\pagestyle{customlandscape}
\begin{landscape}
    Here is the landscaped content, the header of this page should look like the rest...
\end{landscape}


\newpage
\pagestyle{plain}
\lipsum[1-10]
\end{document}

Note : you will have to provide 2 images called tt for it to compile, sorry for that. So, if we look a bit closer, the header of the portrait pages look like this :

portrait page

How can I manage for my landscape pages to look like this ? : landscape page

Currently, by compiling my MWE, you'll notice that the header is on the right on the landscape page.

PS : There is another problem in this MWE, after switching back to portrait, it seems I'm not able to restore the default pagestyle (with the images in the header).

  • Instead of pdflscape you could use graphicx \rotatebox{90}{\begin{minipage}{\textheight}...\end{minipage}} – John Kormylo Feb 3 '15 at 23:07
3

Without lscap package you change page format to landscape by

\newpage

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

here the problem was to adapt the headwidth length

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[left=2cm, right=2cm, bottom=2cm, top=2cm]{geometry}
\setlength{\headheight}{32pt}

\lhead{tt\\Foo}
\rhead{vv\\\thepage}
\cfoot{}

\pagestyle{fancy}
\begin{document}

\lipsum[1-10]

\newlength{\mtL}
\setlength{\mtL}{.8\paperheight}% the next hsize
\addtolength\mtL{-\headwidth}
\newpage
\addtolength\headwidth{\mtL}

%landsape
\pdfpageheight=\paperwidth
\pdfpagewidth=\paperheight
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight

%text width and height
\begingroup 
\vsize=.8\pdfpageheight % do what you like
\hsize=.8\pdfpagewidth  % do what you like
\textwidth=\hsize
\textheight=\vsize
% you can specify the margins

\lipsum[1]

\endgroup
\newpage

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


\pagestyle{plain}
\lipsum[1-10]
\end{document}

edit for more pagestyle{fancy}

\documentclass[a4paper,10pt]{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[left=2cm, right=2cm, bottom=2cm, top=2cm]{geometry}
\setlength{\headheight}{32pt}

\lhead{tt\\Foo}
\rhead{vv\\\thepage}
\cfoot{}

\pagestyle{fancy}
\begin{document}

\lipsum[1-10]

\newlength{\mtL}
\setlength{\mtL}{.8\paperheight}% the next hsize
\addtolength\mtL{-\headwidth}
\newpage
\addtolength\headwidth{\mtL}

%landsape
\pdfpageheight=\paperwidth
\pdfpagewidth=\paperheight
\paperwidth=\pdfpagewidth
\paperheight=\pdfpageheight

%text width and height
\begingroup 
\vsize=.8\pdfpageheight % do what you like
\hsize=.8\pdfpagewidth  % do what you like
\textwidth=\hsize
\textheight=\vsize
% you can specify the margins

\lipsum[1-10]

\endgroup
\newpage
\addtolength\headwidth{-1\mtL}
\paperwidth=\pdfpageheight
\paperheight=\pdfpagewidth
\pdfpageheight=\paperheight
\pdfpagewidth=\paperwidth


\lipsum[1-20]

\pagestyle{plain}
\lipsum[1-10]
\end{document}
  • Thank you for your input. The part which switches to landscape works perfectly, I managed to do it fit my needs. Yet, I am having a problem when switching back to portrait. Using your code, it seems the right part of the header is out of the page on portrait mode, as if a length was not reseted. Any input ? – user17424 Feb 4 '15 at 7:50
  • what do you mean by after landsacap. After landsacape is just befor \pagestyle plain – touhami Feb 4 '15 at 8:03
  • Well imagine the following document : page in portrait > page in portrait > page in landscape > page in landscape > page in portrait. The latter is not properly rendered, as mentioned above. – user17424 Feb 4 '15 at 8:05
  • I edited my ansower – touhami Feb 4 '15 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy