如何在每个部分的标题中添加文字?

如何在每个部分的标题中添加文字?

我让每个页眉上的部分名称正确更改,但其他文本 section.subtitle在每一页上都保持不变。我怎样才能在每个部分的页眉中放置不同的文本?

作为一个肮脏的解决方法,我会重命名每个部分,所以section.name会变成section.name\nsection.subtitle

我知道这远远超出了正确的 mwe,尽管我不记得每个部分在做什么。

\usepackage{titlesec}%
\fancyhead[RO]{\underline{Authorname}\\~\\\leftmark\\section.subtitle}%

\documentclass[12pt,landscape,a4paper,titlepage]{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage{geometry}%
\usepackage[demo]{graphicx}%
\usepackage[english]{babel}%
\usepackage{blindtext}%
\usepackage{xpatch}%
\usepackage{floatrow}%
\usepackage{caption}%
\usepackage{fancyhdr}%
\usepackage{titlesec}%
%
\xpretocmd{\section}{\thispagestyle{plain}}{}{}%
\pagestyle{fancy}%
\title{Jon Doe}%
\author{Authorname | MonthName YYYY}%
\date{}%
\rhead{Authorname}%
\fancyhf{}%
\fancyhead{}%
\renewcommand{\headrulewidth}{0pt}%
\fancyhead[RO]{\underline{Authorname}\\~\\\leftmark\\section.subtitle}%
\renewcommand\sectionmark[1]{\markboth{#1}{}}%
\titleclass{\section}{page}%
\assignpagestyle{\section}{empty}%
\titleformat{\section}[display]{\centering\Huge\bfseries}{\sectionname}{0pt}{\huge}[\clearpage]%
%
\begin{document}%
\normalsize%
\maketitle%
\section*{sectionName}%
\begin{figure}%
\includegraphics[width=\linewidth,height=3cm,keepaspectratio]{/demo}%
\end{figure}%
\pagebreak
\section*{otherSectionName}%
\begin{figure}%
  \includegraphics[width=\linewidth,height=3cm,keepaspectratio]{/demo}%
\end{figure}%
\end{document}

图片

答案1

您目前没有将其\rightmark用于其他用途,因此您可以将字幕存储在那里。但是,您需要在\sectionmark运行之前定义它。

\documentclass[12pt,landscape,a4paper,titlepage]{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage{geometry}%
\usepackage[demo]{graphicx}%
\usepackage[english]{babel}%
\usepackage{blindtext}%
\usepackage{xpatch}%
\usepackage{floatrow}%
\usepackage{caption}%
\usepackage{fancyhdr}%
\usepackage{titlesec}%
%
\xpretocmd{\section}{\thispagestyle{plain}}{}{}%
\pagestyle{fancy}%
\title{Jon Doe}%
\author{Authorname | MonthName YYYY}%
\date{}%
\rhead{Authorname}%
\fancyhf{}%
\fancyhead{}%
\renewcommand{\headrulewidth}{0pt}%
\fancyhead[RO]{\underline{Authorname}\\\vskip\baselineskip\leftmark\\\rightmark}%
\renewcommand\sectionmark[1]{\markboth{#1}{\mysubtitle}}%
\titleclass{\section}{page}%
\assignpagestyle{\section}{empty}%
\titleformat{\section}[display]{\centering\Huge\bfseries}{\sectionname}{0pt}{\huge}[\clearpage]%
%
\newcommand{\subtitle}[1]{\gdef\mysubtitle{#1}\ignorespaces}
%
\begin{document}%
\normalsize%
\maketitle%
\subtitle{First subtitle}
\section*{sectionName}
\begin{figure}%
\includegraphics[width=\linewidth,height=3cm,keepaspectratio]{/demo}%
\end{figure}%
\pagebreak
\subtitle{Second subtitle}
\section*{otherSectionName}
\begin{figure}%
  \includegraphics[width=\linewidth,height=3cm,keepaspectratio]{/demo}%
\end{figure}%
\end{document}

相关内容