第一节页面的页眉中忽略了节标记命令

第一节页面的页眉中忽略了节标记命令

我的book xetex文档中的一些章节标题fancyhdr太长,无法放入页眉。我使用\sectionmarkint 来为页眉设置一个较短的版本。这很有效(参见 MWE 的最后一页),
缩短章节标题
但不在该部分的第一页(如果该页恰好是奇数页,其中显示部分页眉,请参阅 MWE 的第 3 页)。
完整章节标题

我该怎么做才能让编译器尊重它\sectionmark

梅威瑟:

\documentclass[10pt]{book}
\usepackage[nobottomtitles]{titlesec}
\usepackage{kantlipsum}
\usepackage{fancyhdr}
\makeatletter%hier definition schriftgrößen-makro
  \newcommand\chapsize{\@setfontsize\chapsize{13pt}{6}}
  \newcommand\secsize{\@setfontsize\secsize{11.5pt}{6}}
  \newcommand\pnsize{\@setfontsize\pnsize{10.5pt}{6}}
  \newcommand\appsize{\@setfontsize\appsize{9pt}{6}}
\makeatother

\titleformat{\chapter}[hang]
   {\chapsize\centering}{\thechapter.\ }{0pt}{}
\titleformat{\section}[hang] 
    {\secsize\centering}{\thesection\ }{0pt}{}
\titlespacing*{\chapter}{0pt}{0pt}{8mm}
\titlespacing*{\section}{0pt}{24pt}{4.233mm}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyfoot[LE,RO]{\pnsize{\thepage}}
\fancyhead[CO]{\fontsize{9.5}{10.5}\selectfont\scshape\MakeLowercase{\rightmark}}
\fancyhead[CE]{\fontsize{9.5}{10.5}\selectfont\scshape\MakeLowercase{\leftmark}}
\renewcommand{\headrulewidth}{0pt}


\begin{document}

\chapter{Chapter One}
\section{First Section}
\kant[1-7]
\section{Second section: Too much text for a running head}
\sectionmark{Second section}
\kant[8-15]
\end{document}

答案1

通过简化代码前言代码来回答(但使用户使用更加困难)根据 OP 的要求:

你可以更换你的\renewcommand{\sectionmark}[1]{\markright{#1}}

经过\renewcommand{\sectionmark}[1]{\gdef\rightmark{#1}}

\documentclass[10pt]{book}
\usepackage[nobottomtitles]{titlesec}
\usepackage{kantlipsum}
\usepackage{fancyhdr}
\makeatletter%hier definition schriftgrößen-makro
  \newcommand\chapsize{\@setfontsize\chapsize{13pt}{6}}
  \newcommand\secsize{\@setfontsize\secsize{11.5pt}{6}}
  \newcommand\pnsize{\@setfontsize\pnsize{10.5pt}{6}}
  \newcommand\appsize{\@setfontsize\appsize{9pt}{6}}
\makeatother

\titleformat{\chapter}[hang]
   {\chapsize\centering}{\thechapter.\ }{0pt}{}
\titleformat{\section}[hang] 
    {\secsize\centering}{\thesection\ }{0pt}{}
\titlespacing*{\chapter}{0pt}{0pt}{8mm}
\titlespacing*{\section}{0pt}{24pt}{4.233mm}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\gdef\rightmark{#1}}
\fancyhf{}
\fancyfoot[LE,RO]{\pnsize{\thepage}}
\fancyhead[CO]{\fontsize{9.5}{10.5}\selectfont\scshape\MakeLowercase{\rightmark}}
\fancyhead[CE]{\fontsize{9.5}{10.5}\selectfont\scshape\MakeLowercase{\leftmark}}
\renewcommand{\headrulewidth}{0pt}


\begin{document}

\chapter{Chapter One}
\section{First Section}
\kant[1-7]
\section{Second section: Too much text for a running head}
\sectionmark{Second section}
\kant[8-15]
\end{document}

\section旧答案:自动化(添加命令的定义\sectionmark

您可以根据我的帖子重新定义部分这里具有使用“加星号”部分的额外能力,但带有可选参数,这意味着它将是一个带有更改的普通(非加星号)部分\sectionmark

请参阅下面更改后的 MWE 中的工作原理:

\documentclass[10pt]{book}
\usepackage[nobottomtitles]{titlesec}
\usepackage{kantlipsum}
\usepackage{fancyhdr}
\makeatletter%hier definition schriftgrößen-makro
  \newcommand\chapsize{\@setfontsize\chapsize{13pt}{6}}
  \newcommand\secsize{\@setfontsize\secsize{11.5pt}{6}}
  \newcommand\pnsize{\@setfontsize\pnsize{10.5pt}{6}}
  \newcommand\appsize{\@setfontsize\appsize{9pt}{6}}
\makeatother

\titleformat{\chapter}[hang]
   {\chapsize\centering}{\thechapter.\ }{0pt}{}
\titleformat{\section}[hang] 
    {\secsize\centering}{\thesection\ }{0pt}{}
\titlespacing*{\chapter}{0pt}{0pt}{8mm}
\titlespacing*{\section}{0pt}{24pt}{4.233mm}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\gdef\rightmark{#1}}
\fancyhf{}
\fancyfoot[LE,RO]{\pnsize{\thepage}}
\fancyhead[CO]{\fontsize{9.5}{10.5}\selectfont\scshape\MakeLowercase{\rightmark}}
\fancyhead[CE]{\fontsize{9.5}{10.5}\selectfont\scshape\MakeLowercase{\leftmark}}
\renewcommand{\headrulewidth}{0pt}

\let\oldsection\section
\makeatletter
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have optional parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%%
\oldsection{#2}\sectionmark{#1}%
}
\def\@StarredWithout#1{%
\oldsection*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldsection[#1]{#2}%
}
\def\@nonStarredWithout#1{%
\oldsection{#1}%
}
\makeatother 

\begin{document}

\chapter{Chapter One}
\section{First Section}
\kant[1-7]
\section*[Second section]{Second section: Too much text for a running head}
\kant[8-15]
\end{document}

答案2

\sectionmark只需在前面添加\section

\sectionmark{Second section}
\section{Second section: Too much text for a running head}
\sectionmark{Second section}

相关内容