5

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}
user2763361
  • 435
  • 2
  • 11
  • I'm currently working on a LaTeX 3 answer to this, but check out the other answer. http://tex.stackexchange.com/questions/122792/breadcrumb-hyperlink-header – Sean Allred Oct 17 '13 at 04:20
  • Does this help? http://tex.stackexchange.com/q/79664/34618 – Jesse Oct 17 '13 at 06:28

2 Answers2

3

The landscape business is irrelevant for the problem. However, rather than changing \pdfpageattr yourself, it's better to load pdflscape that modifies the landscape environment to do the right thing.

Here's how you can do:

\documentclass{article}

\usepackage{lipsum} % for mock text

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} % clear all header fields
\renewcommand{\headrulewidth}{0pt} % no line in header area
\fancyfoot{} % clear all footer fields
\fancyfoot[R]{\thepage}  % page number in "outer" position of footer line
% other info in "inner" position of footer line
\fancyfoot[L]{\hyperlink{contents}{Click here go back}}
\renewcommand{\sectionmark}[1]{\markboth{\thesection. #1}{}}
\renewcommand{\subsectionmark}[1]{\markright{\thesubsection. #1}}
\fancyhead[L]{%
  \begin{tabular}{@{}l@{}}
  \leftmark\\
  \rightmark
  \end{tabular}%
}
\setlength{\headheight}{24pt}

\usepackage{hyperref}

\begin{document}

\hypertarget{contents}{}\tableofcontents
\clearpage

\section{sec}
\subsection{subsec}
\lipsum[1-20]

\end{document}

However, due to inherent limitations of LaTeX's mark mechanism, the first subsection may not be shown in the page header where it appears.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
egreg
  • 1,121,712
0

I ended up with a beautiful result manually. I used \addcontentsline to create invisible headings and subheadings, then used \lhead{sectionname: \emph{subsectionname}} to create the effect that I wanted.

This is more manual and less extensible but is acceptable for what I'm using it for.

If others have more automated solutions I will give them the correct answer.

user2763361
  • 435
  • 2
  • 11