1

I have a document in portrait with tables I want to be in landscape. I want to have the same headers on every page, on the left and right and the section number as a footer on the right. This works ok on portrait, though the footer does not appear. I have gone through numerous posts on rotating headers and footers in landscape. I still have the following problems 1. The headers are appearing at the bottom, not at the top in landscape 2. The header rule is not rotated in lanscape I would appreciate assistance. My code is below.

\documentclass[english]{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage{everypage}
\usepackage{afterpage}
\usepackage{flafter}

\usepackage{array,booktabs,tabularx} % also loads 'array' package
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of 'X' columns
\usepackage{ltablex} 
\usepackage{longtable}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=12mm]{geometry}
\usepackage{lscape,graphicx}
\usepackage[absolute]{textpos}
\usepackage{fancyhdr}

\fancypagestyle{portr}{% 
\fancyhf{} % clear all header and footer fields 
\fancyhead[L]{\scriptsize Project Report}
\fancyhead[R]{\scriptsize Name of Project}
\fancyfoot[RO,LE]{\scriptsize \leftmark}
}

\fancypagestyle{lscape}{% 
\fancyhf{} % clear all header and footer fields 
\fancyfoot[R]{%
\begin{textblock}{20}(1,5){\rotatebox{90}{\leftmark}}\end{textblock}
}
\fancyhead[L] {%
\begin{textblock}{1}(13,10.5){\rotatebox{90}{Project Report}}\end{textblock}
}
\fancyhead[R] {%
\begin{textblock}{1}(13,10.5){\rotatebox{90}{Name of Project}}\end{textblock}
}
}
\setlength{\TPHorizModule}{1cm}
\setlength{\TPVertModule}{1cm}

\newlength{\hfoot}
\newlength{\vfoot}
\AddEverypageHook{\ifdim\textwidth=\linewidth\relax
\else\setlength{\hfoot}{-\topmargin}%
\addtolength{\hfoot}{-\headheight}%
\addtolength{\hfoot}{-\headsep}%
\addtolength{\hfoot}{-.5\linewidth}%
\ifodd\value{page}\setlength{\vfoot}{\oddsidemargin}%
\else\setlength{\vfoot}{\evensidemargin}\fi%
\addtolength{\vfoot}{\textheight}%
\addtolength{\vfoot}{\footskip}%
\raisebox{\hfoot}[0pt][0pt]{\rlap{\hspace{\vfoot}\rotatebox[origin=cB]{90}{\thepage}}}\fi}

\begin{document}
\thispagestyle{portr}
\noindent Test 1 2 3.

\pagebreak{}
\noindent Test 4 5 6.

\pagebreak{}

\newgeometry{hmargin=3cm,vmargin=3cm}
\thispagestyle{lscape}
\pagestyle{lscape}
\begin{landscape}
\section{Appendix 1}
\normalsize 

{\renewcommand{\arraystretch}{2}%
\begin{longtable}[H]{| p{4cm} | p{4cm}  | p{2cm} | p{11cm} |}
\caption{Appendix} \label{tab:appndx1}
\\\hline
\toprule
header1 & header2 & header3 & header4 
\\[0.25cm]
\hline
text11
&
text12
&
text13
&
\parbox{.72\textwidth}{text140\\text141
}
\\[0.25cm]
\hline
text21
&
text22
&
text23
&
\parbox{.72\textwidth}{text240\\text241
}
\\[0.25cm]
\hline
text31
&
text32
&
text33
&
\parbox{.72\textwidth}{text340\\text341
}
\\[0.25cm]
\hline
text41
&
text42
&
text43
&
\parbox{.72\textwidth}{text440\\text441
}
\\[0.25cm]
\hline
text51
&
text52
&
text53
&
\parbox{.72\textwidth}{text540\\text541
}
\\[0.25cm]
\bottomrule
\end{longtable}
}

\pagebreak{}
\section{Appendix 2}
{\renewcommand{\arraystretch}{2}%
\begin{longtable}[H]{| p{4cm} | p{4cm}  | p{2cm} | p{11cm} |}
\caption{Appendix} \label{tab:appndx2}
\\\hline
\toprule
header1 & header2 & header3 & header4 
\\[0.25cm]
\hline
text11
&
text12
&
text13
&
\parbox{.72\textwidth}{text140\\text141
}
\\[0.25cm]
\hline
text21
&
text22
&
text23
&
\parbox{.72\textwidth}{text240\\text241
}
\\[0.25cm]
\hline
text31
&
text32
&
text33
&
\parbox{.72\textwidth}{text340\\text341
}
\\[0.25cm]
\hline
text41
&
text42
&
text43
&
\parbox{.72\textwidth}{text440\\text441
}
\\[0.25cm]
\hline
text51
&
text52
&
text53
&
\parbox{.72\textwidth}{text540\\text541
}
\\[0.25cm]
\bottomrule
\end{longtable}
}
\end{landscape}

\pagestyle{plain}
\end{document}
Zilore Mumba
  • 1,087
  • 1
    For a printed document, you want the headers and footers to appear in the same place on every page. In fact, the relative sizes and positions of the text area and margins remain the same in landscape. Nor does fancyhdr respond well to changes in geometry. I would implement my own header/footer code using the everypage package. – John Kormylo Aug 07 '18 at 13:55

1 Answers1

2

To get an output for \leftmark with your example you have to use \pagestyle{fancy} at least once. This could be in the preamble.

With an uptodate KOMA-Script version you could use a combination of packages typearea (with option usegeometry) and geometry to switch between portrait and landscape. Then you can use pagestyle fancy for both portrait and landscape pages.

\documentclass[english]{article}
\usepackage[usegeometry]{typearea}% load before geometry
\usepackage[a4paper,width=150mm,vmargin=25mm,bindingoffset=12mm]{geometry}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all header and footer fields 
\fancyhead[L]{\scriptsize Project Report}
\fancyhead[R]{\scriptsize Name of Project}
\fancyfoot[RO,LE]{\scriptsize \leftmark}

\usepackage{blindtext}% only for dummy text
%\usepackage{showframe}% only to show the page layout

\begin{document}
\blinddocument

\clearpage
\KOMAoptions{paper=landscape,DIV=last}
%\newgeometry{margin=3cm}
\newgeometry{hmargin=2.5cm,bottom=25mm,height=150mm,includehead}
\fancyheadoffset{0pt}% recalculate headwidth for fancyhdr
\blinddocument

\clearpage
\KOMAoptions{paper=portrait,DIV=last}
\restoregeometry
\fancyheadoffset{0pt}
\blinddocument
\end{document}

Result:

enter image description here

esdd
  • 85,675