我的 TeX 文档有一个\section with a too long text, so I'd like to change header by
\markright`,内容类似 ^
\section{Too long text}
\markright{\thesection. Shorter text}
但是,正如帮助所承诺的那样,右标题是由页面上的第一个\markright
或设置的,因此上面的代码标题包含太长的文本(由生成)。代码\markboth
\section
\markright{\thesection. Shorter text}
\section{Too long text}
几乎满足要求,除了文本数字比应有的数字少 1,因为增加的数字\section
就在下面。因此,需要编写类似
\stepcounter{section}
\markright{\thesection. Shorter text}
\addtocounter{section}{-1}
\section{Too long text}
它给出了解决方案,但对于如此简单的任务来说似乎太棘手了。 有一个可选参数,\section
但它不仅会更改标题,还会更改内容中的行,这是不必要的。
那么,是否可以用简单的方法更改“\section”后的标题?
答案1
请尝试此代码
\documentclass[10pt, a4paper,twoside]{article}
\usepackage{kantlipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{plain}{}
\fancyhf{}
\fancyhead[RE,LO]{\rmfamily \small \nouppercase \rightmark}
\begin{document}
\pagestyle{fancy}
\section{Abstract \protect\markboth{Abstract}{Abstract} }
\kant[1]
\clearpage
\section{A very long title perhaps two lines \protect\markboth{Short title I }{Short title I}}
\kant[2-5]
\clearpage
\section{A much longer title perhaps two lines o more A much longer title perhaps two lines o more \protect\markboth{Short title II}{Short title II}}
\kant[6-9]
\clearpage
\section{Normal title}
\kant[10-12]
\end{document}
答案2
无论如何,您都需要更改标题,因为大写倾斜标题的样式确实很糟糕。
我建议一个\doubletitle
命令,用于长节(或章节)标题;第一个参数是长标题,第二个参数是简称。
\documentclass{book}
\usepackage{fancyhdr}
\usepackage{lipsum} % for mock text
\fancyhf{} % clear all fields
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\shorttrue\nouppercase{\leftmark}}
\fancyhead[LO]{\shorttrue\nouppercase{\rightmark}}
\pagestyle{fancy}
\newif\ifshort
\DeclareRobustCommand{\doubletitle}[2]{\ifshort #2\else #1\fi}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Title}
\section{\doubletitle{First Here we have a very very very very very very very very very
very very very very very very very very very very very very long title}{First}}
\lipsum[1-20]
\section{\doubletitle{Second Here we have a very very very very very very very very very
very very very very very very very very very very very very long title}{Second}}
\lipsum[1-20]
\section{Short title}
\lipsum[1-20]
\end{document}
您可以考虑使用具有内置机制的memoir
代替,该机制具有两个可选参数用于分段命令。book
答案3
尝试memoir
类(包括book
、report
和article
)类。文档划分可能采用两个可选参数,分别用于目录文本和标题文本。例如:
\section{<toc-title>][<head-title>]{<title>}
<title>
目录、标题和文档中没有使用可选参数;<title>
始终用于文档。<toc-title>
一个用于 ToC 和 header 的可选参数。<toc-title>
目录的两个可选参数,<head-title>
用于标题。