我正在book
写titlesec
并尝试在部分从相应页面顶部开始时隐藏包含部分名称的标题。鉴于我的所有部分都从新页面开始\assignpagestyle
,我尝试了,但不起作用。手动添加\thispagestyle
每个部分有效,但应该有更好的解决方案。
\documentclass[a4paper,12pt]{book}
\usepackage[pagestyles]{titlesec}
\renewpagestyle{headings}{%
\sethead[\chaptertitle][][]
{}{}{\thesection~\sectiontitle}%
\setfoot{}{\thepage}{}%
}
\renewpagestyle{plain}{%
\setfoot{}{\thepage}{}%
}
\pagestyle{headings}
\newpagestyle{section}{%
\sethead[\chaptertitle][][]
{}{}{}%
\setfoot{}{\thepage}{}%
}
\assignpagestyle{\section}{section}
\begin{document}
\chapter{header ok}
\clearpage
\section{First} % warning here
even page
\clearpage
\section{Second} % warning here
suppress header here, odd page, start section on top
\clearpage
chapter headers are ok, even page
\clearpage
keep header here, odd page, no new section
\end{document}
使用 MikTeX 2.8 我收到以下警告:
Package titlesec Warning: Page style in straigh class ignored on input line <XXX>
答案1
将以下内容添加到您的序言中:
\usepackage{xpatch}
\xpretocmd{\section}{\thispagestyle{plain}}{}{}
或者你只想隐藏以下标题奇怪的包含章节标题的页面:
\usepackage{xpatch}
\usepackage{scrextend}
\xpretocmd{\section}{\ifthispageodd{\thispagestyle{plain}}{}}{}{}
答案2
警告
Package titlesec Warning: Page style in straight class ignored on input line 30
提示您有关问题的信息:您为部分页面定义的页面样式未应用,原因是\section
默认情况下(使用titlesec
术语)straight
类;即,旨在在文本中间生成标题。要允许应用页面样式,您可以将类更改\section
为top
:
\titleclass{\section}{top}
这与\newcommand\sectionbreak{\clearpage}
将产生所需的结果(使用来校正章节标题的间距\titlespacing{\section}{0pt}{*-3}{*1.5}
):
\documentclass[a4paper,12pt]{book}
\usepackage[pagestyles]{titlesec}
\titleclass\section{top}
\newcommand\sectionbreak{\clearpage}
\titlespacing{\section}{0pt}{*-3}{*1.5}
\renewpagestyle{headings}{%
\sethead[\chaptertitle][][]
{}{}{\thesection~\sectiontitle}%
\setfoot{}{\thepage}{}%
}
\renewpagestyle{plain}{%
\setfoot{}{\thepage}{}%
}
\pagestyle{headings}
\newpagestyle{section}{%
\sethead[\chaptertitle][][]
{}{}{}%
\setfoot{}{\thepage}{}%
}
\assignpagestyle{\section}{section}
\begin{document}
\chapter{header ok}
\clearpage
\section{First} % warning here
even page
\clearpage
\section{Second} % warning here
suppress header here, odd page, start section on top
\clearpage
chapter headers are ok, even page
\clearpage
keep header here, odd page, no new section
\end{document}