将章节和小节放在页眉中

将章节和小节放在页眉中

我使用LaTeX显示landscape longtable。由于内容的性质,我经常有sectionsubsection、 ,subsubsection并且我使用paragraph代理subsubsubsection(通过titlesec)。我还使用pdfpageattr旋转页面

鉴于页面布局和longtable我的真实示例中所有 s 的宽度(宽度未反映在下面的玩具示例中),我无法在同一页面上显示标题/副标题。将会发生的情况是,标题/副标题将像正常一样显示,但随后会出现一个空白页,并且长表将出现在下一页上。

我想通过在标题中放置section/来解决这个问题。在下面的例子中,我希望所有 4 行s/都位于 中。我该怎么做?subsectionsectionsubsectionheader

我倾向于将标题放在旋转页面的左侧边缘(这样当我以 90 度倾斜查看页面时,我可以正常阅读标题而无需低下头)。但正确的答案可以简单地将各部分包含在正常的标题位置中。

\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}

答案1

业务landscape与问题无关。不过,与其改变\pdfpageattr自​​己,不如pdflscape改变landscape环境来做正确的事情。

您可以这样做:

\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}

然而,由于 LaTeX 标记机制的固有限制,第一个小节可能不会显示在它出现的页眉中。

答案2

我最终手动获得了漂亮的结果。我过去常常\addcontentsline创建不可见的标题和副标题,然后用它\lhead{sectionname: \emph{subsectionname}}来创建我想要的效果。

这是更加手动和更不可扩展的,但对于我使用它的目的来说是可以接受的。

如果其他人有更多自动化解决方案,我会给他们正确的答案。

相关内容