fancyhdr 长节名称与页码重叠

fancyhdr 长节名称与页码重叠

您好,我使用了花式页眉,但页码与页眉中的节名重叠。有没有办法强制将文本缩小一点,或者只允许页眉中的边距更长?谢谢。

口粮:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE]{\small\leftmark}%left on even
\fancyhead[RO]{\small\rightmark}%right on odd
\fancyhead[RE,LO]{ {\textbf{Page \thepage}} } %page number is right on even left on odd
\pagestyle{fancy}
\begin{document}
\chapter{Introduction}
\section{something}
Filler text
\subsection{something something}
Filler text
\newpage
\section{REALLY REALLY LONG TITLE OF SECTION}
\newpage
\section{REALLY REALLYy REALLY REALLY LONG TITLE OF SECTION}
\end{document}

答案1

正常的方式是使用\section[short title for ToC and header]{Long title for main document}

\section[ABBREVIATED TITLE]{REALLY REALLY REALLY REALLY REALLY REALLY LONG TITLE OF SECTION}

我确信您可以缩写标题文本以适合页眉(和目录);它们基本上是显示章节标题全部魅力的指示器。

答案2

仅在需要时才使用 adjustbox 来减少宽度。

\documentclass{book}
\usepackage[headheight=20pt]{geometry}
\usepackage[utf8]{inputenc}
\newlength{\markwidth}
\newcommand{\setmarkwidth}{\sbox0{\textbf{Page \thepage}}%
  \setlength{\markwidth}{\dimexpr\textwidth-\columnsep-\wd0}%
  \ifodd\value{page}
    \sbox1{\rightmark}%
    \ifdim\wd1<\markwidth \setlength{\markwidth}{\wd1}\fi
  \else
    \sbox1{\leftmark}%
    \ifdim\wd1<\markwidth \setlength{\markwidth}{\wd1}\fi
  \fi}
\usepackage{adjustbox}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE]{\setmarkwidth\adjustbox{width=\markwidth}{\leftmark}}%left on even
\fancyhead[RO]{\setmarkwidth\adjustbox{width=\markwidth}{\rightmark}}%right on odd
\fancyhead[RE,LO]{ {\textbf{Page \thepage}} } %page number is right on even left on odd
\pagestyle{fancy}
\begin{document}
\chapter{Introduction}
\section{something}
Filler text
\subsection{something something}
Filler text
\newpage
\section{REALLY REALLY REALLY REALLY REALLY REALLY LONG TITLE OF SECTION}
\newpage
some text here
\end{document}

答案3

您还可以仅在标题中使用短标题,而保留主要内容中的目录条目和章节标题不变:

\section{Large title}
\sectionmark{Short title}
\label{sec:label}

答案4

您可以重新定义这些命令,将章节标题包装在自定义长度的框中(或减小章节标题字体大小):

\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter . \parbox[t]{0.45\textwidth{\textit{#1}}}{}}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ \parbox[t]{0.45\textwidth}{#1}}}

相关内容