I am using LaTeX to display landscape longtables. Due to the nature of the contents, I regularly have sections, subsections, subsubsections and I use paragraph to proxy subsubsubsections (through titlesec). I also use pdfpageattr to rotate the page
Given the layout of the page and the width of all the longtables in my real-world example (width not reflected in toy example below), I cannot display the headings/subheadings on the same page. What will happen is that the headings/subheadings will show like normal but then there will be a blank page that follows, and the longtable will come on the following page.
I want to fix this by placing the section/subsection in the header. In the example below I would like all 4 lines of sections/subsections to be in the header. How do I do this?
My preference is for the headers to be in the left hand margin of the rotated page (so when I'm viewing the page on the 90 degree tilt, I can read the heading as normal without bending my head). But the correct answer could simply include the sections in the normal header location.
\documentclass{article}
\usepackage{longtable}
\usepackage{lscape} %Landscap pages
\usepackage{hyperref} %Clickable links
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\usepackage{titlesec} %paragraph as subsubsubsection
\setcounter{secnumdepth}{4}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\setcounter{tocdepth}{5}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} % clear all header fields
\renewcommand{\headrulewidth}{0pt} % no line in header area
\fancyfoot{} % clear all footer fields
\fancyfoot[LE,RO]{\thepage} % page number in "outer" position of footer line
\fancyfoot[RE,LO]{\hyperlink{contents}{Click here go back}} % other info in "inner" position of footer line
\begin{document}
\tableofcontents
\newpage
\section{sec}
\subsection{subsec}
\subsubsection{subsubsec}
\paragraph{subsubsubsec}
\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}
\begin{landscape}
\begin{longtable}{r}\caption{test} \tabularnewline
\hline\hline
\multicolumn{1}{c}{}\tabularnewline
\hline
\endfirsthead\caption[]{\em (continued)} \tabularnewline
\hline
\multicolumn{1}{c}{}\tabularnewline
\hline
\endhead
\hline
\endfoot
\label{c}
$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline$1$\tabularnewline
\hline
\end{longtable}
\end{landscape}
\end{document}