页眉上的章节编号错误(首页除外)

发布于 2024-08-21 08:04:03 字数 1930 浏览 4 评论 0原文

我正在用 Latex 写论文并有一个模板。除了一件事情之外,它对其他所有事情都很有效。章节编号在每章的第一页上正确递增,但对于每章的连续页面,标题“第 x 章 - 这是章节标题”的章节编号始终为 1。

以下是 CLS 文件中的代码示例,我认为它与标头相关:

\newcommand\btypeout[1]{\bhrule\typeout{\space #1}\bhrule}
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space \number\year}
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{0pt}
\setlength{\parskip}{2.0ex plus0.5ex minus0.2ex}
\usepackage{vmargin}
\setmarginsrb           { 1.5in}  % left margin
                        { 0.6in}  % top margin
                        { 1.0in}  % right margin
                        { 0.8in}  % bottom margin
                        {  20pt}  % head height
                        {0.25in}  % head sep
                        {   9pt}  % foot height
                        { 0.3in}  % foot sep
\raggedbottom
\setlength{\topskip}{1\topskip \@plus 5\p@}
\doublehyphendemerits=10000       % No consecutive line hyphens.
\brokenpenalty=10000              % No broken words across columns/pages.
\widowpenalty=9999                % Almost no widows at bottom of page.
\clubpenalty=9999                 % Almost no orphans at top of page.
\interfootnotelinepenalty=9999    % Almost never break footnotes.
\usepackage{fancyhdr}
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}\lfoot{}\rfoot{}\cfoot{}
\pagestyle{fancy}

%% Chapter Heading ---------------
\renewcommand{\chaptermark}[1]{\btypeout{\thechapter\space #1}\markboth{\@chapapp\ \thechapter\ #1}{\@chapapp\ \thechapter\ #1}}

%%--------------------------------------------------
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}

I am writing up my thesis in Latex and have a template. It works nicely for every thing else except one. Chapter numbers are correctly incremented on the first page of each chapter but for consecutive pages of each chapter, the header saying "Chapter x - This is a chapter title" have 1 always as chapter number.

Following is the code sample from the CLS file which i think is relevant to the headers:

\newcommand\btypeout[1]{\bhrule\typeout{\space #1}\bhrule}
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space \number\year}
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{0pt}
\setlength{\parskip}{2.0ex plus0.5ex minus0.2ex}
\usepackage{vmargin}
\setmarginsrb           { 1.5in}  % left margin
                        { 0.6in}  % top margin
                        { 1.0in}  % right margin
                        { 0.8in}  % bottom margin
                        {  20pt}  % head height
                        {0.25in}  % head sep
                        {   9pt}  % foot height
                        { 0.3in}  % foot sep
\raggedbottom
\setlength{\topskip}{1\topskip \@plus 5\p@}
\doublehyphendemerits=10000       % No consecutive line hyphens.
\brokenpenalty=10000              % No broken words across columns/pages.
\widowpenalty=9999                % Almost no widows at bottom of page.
\clubpenalty=9999                 % Almost no orphans at top of page.
\interfootnotelinepenalty=9999    % Almost never break footnotes.
\usepackage{fancyhdr}
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}\lfoot{}\rfoot{}\cfoot{}
\pagestyle{fancy}

%% Chapter Heading ---------------
\renewcommand{\chaptermark}[1]{\btypeout{\thechapter\space #1}\markboth{\@chapapp\ \thechapter\ #1}{\@chapapp\ \thechapter\ #1}}

%%--------------------------------------------------
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

櫻之舞 2024-08-28 08:04:03

虽然我没有使用与您相同的模板,但我对类似问题的解决方案涉及三个包:sectsty、fancyhdr 和partpg(我重写了chappg,以使各部分具有与chappg 对章节相同的效果)。

我列出了标题代码的以下部分。您将从我在该代码中的注释中看到,仍然存在一个未解决的问题,但注释给出了一种解决方法。

%----------------------------------------------------------
\usepackage{sectsty} % Fancy section Headers.
\usepackage{fancyhdr} % Headers and footers.
\usepackage[auto]{partpg} % Modified version of chappg to provide part-pageno type page numbering.
\usepackage{appendix} % Multiple appendix sections in multi part document.
\usepackage[style=altlist,toc=true]{glossary} % Enhanced glossary commands.
%----------------------------------------------------------
\makeglossary
% There is a conflict between partpg and makeglos.
% To generate the glossary, run makeglos AFTER removing the next line.
\renewcommand{\partpgsep}{.}
\renewcommand{\glossaryname}{Glossary}
\setlength{\headheight}{13.6pt}
\pagestyle{fancy}%
{% Ensure appendices in different parts restart numbering at A each time 
\renewcommand{\restoreapp}{} 

\fancypagestyle{plain}{% Redefine style to use the relevant elements on the part pages
\fancyhfoffset[LE,RO]{\marginparsep+\marginparwidth}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0.1pt}
\fancyhead[LE,RO]{\leftmark}
\fancyfoot[LE,RO]{\thepage}}%

\makeatletter% Redefine cleardoublepage so blank pages at the end of chapters have desired header.
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \vspace*{\fill}
  \pagestyle{plain}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

\fancyhead{}
\fancyfoot{}
%----------------------------------------------------------
\begin{document}
\end{document}
%----------------------------------------------------------

如果这会带您前进,并且您想了解我在partpg中编码的详细信息,请对此答案发表评论。

Although I am not using the same template as you, my solution to a similar problem involved three packages: sectsty, fancyhdr, and partpg (my rewriting of chappg to give the same effect to parts as chappg does for chapters).

I set out below portions of my header code. You will see from my comments in that code that there is still one unresolved problem, but the comments give a workaround.

%----------------------------------------------------------
\usepackage{sectsty} % Fancy section Headers.
\usepackage{fancyhdr} % Headers and footers.
\usepackage[auto]{partpg} % Modified version of chappg to provide part-pageno type page numbering.
\usepackage{appendix} % Multiple appendix sections in multi part document.
\usepackage[style=altlist,toc=true]{glossary} % Enhanced glossary commands.
%----------------------------------------------------------
\makeglossary
% There is a conflict between partpg and makeglos.
% To generate the glossary, run makeglos AFTER removing the next line.
\renewcommand{\partpgsep}{.}
\renewcommand{\glossaryname}{Glossary}
\setlength{\headheight}{13.6pt}
\pagestyle{fancy}%
{% Ensure appendices in different parts restart numbering at A each time 
\renewcommand{\restoreapp}{} 

\fancypagestyle{plain}{% Redefine style to use the relevant elements on the part pages
\fancyhfoffset[LE,RO]{\marginparsep+\marginparwidth}
\renewcommand{\headrulewidth}{0.1pt}
\renewcommand{\footrulewidth}{0.1pt}
\fancyhead[LE,RO]{\leftmark}
\fancyfoot[LE,RO]{\thepage}}%

\makeatletter% Redefine cleardoublepage so blank pages at the end of chapters have desired header.
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
  \hbox{}
  \vspace*{\fill}
  \pagestyle{plain}
  \newpage
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother

\fancyhead{}
\fancyfoot{}
%----------------------------------------------------------
\begin{document}
\end{document}
%----------------------------------------------------------

If this takes you forward, and you want to have details of my coding in partpg please comment on this answer.

我很坚强 2024-08-28 08:04:03

您是否尝试过在使用 fancyhdr 包调用命令之前清除页眉和页脚?

像这样的东西:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} % Clear Headers
\fancyfoot{} % Clear Footers
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}\lfoot{}\rfoot{}\cfoot{}

have you tried clearing the headers and footers before calling commands into them with the fancyhdr package?

something like this:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{} % Clear Headers
\fancyfoot{} % Clear Footers
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}\lfoot{}\rfoot{}\cfoot{}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文