右上角显示“目录”而不是章节标题

右上角显示“目录”而不是章节标题

我有一个类MyReportClass,用于定义文档所有页面的页边距中必须显示的内容。特别是,我希望当前部分显示在每页的右上边缘。但是,从目录开始,我得到的是“目录”,而不是章节编号和标题。当通过命令创建参考部分时\bibliography,右上边缘会显示“参考”,并将其保留在文档末尾的附录中。

在此处输入图片描述

我的课程命令有问题吗?

以下是我的情况的 MWE。

\documentclass{MyReportClass}

\begin{document}

\reporttitle{My Title}
    \coursecode{1234}
    \coursename{Course Name}
    \instructorname{Instructor Name}
    \reportauthor{Name}{Surname}{1234}
    \frontcoverpic{example-image-b}

    \initialise

    \section{Section 1}
    \newpage\section{Section 2}

\end{document}

\makemarings命令MyReportClass

\newcommand{\makemargins}{
\makenomenclature
\pagestyle{fancy}
\fancyheadoffset{1cm}
\setlength{\headheight}{2cm}
\lhead{\includegraphics[width=0.15\textwidth]{./logos/logo.pdf}} % Set image at top of the page
\rhead{\nouppercase{\leftmark}}
\rfoot{\thepage}
\cfoot{\textbf{\reporttitle}}
\lfoot{\coursecode}
}

\initialize命令MyReportClass

\newcommand{\initialise}{
    \makemargins
    \makecoverpage
    \tableofcontents
    \newpage
}

供参考,以下是完整的MyReportClass

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyReportClass}
\LoadClass[a4paper,12pt]{article} % Class of the document

%--------------------- Packages ------------------------

\RequirePackage[english]{babel} % Langueage of the document
\RequirePackage[utf8]{inputenc} % Special characters
\RequirePackage[section]{placeins} % For format of sections
\RequirePackage[T1]{fontenc} % Letters not included in UTF-8
\RequirePackage{mathtools} % Equations and mathematic symbols
\RequirePackage{siunitx} % Scientific notation
\RequirePackage{float} % Images formatting
\RequirePackage{graphicx} % Insert figures
\RequirePackage{tikz}
\RequirePackage[justification=centering]{caption} % Centred legends
\RequirePackage{subcaption}
\RequirePackage{wallpaper}
\RequirePackage{nomencl}
\RequirePackage{fancyhdr}
\RequirePackage{url}
\RequirePackage[pdfencoding=auto,psdextra,hidelinks]{hyperref} % Legends in sub-figures
\RequirePackage{amsmath,bm,amssymb}
\RequirePackage{amsfonts}
\RequirePackage{bookmark} % Faster updated bookmarks
\RequirePackage{textcomp}

% Package for nice tables
\RequirePackage{booktabs,makecell}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\sisetup{
    %  output-decimal-marker = {,},
    detect-weight,
    mode = text
}
\newcommand*{\specialcell}[2][b]{%
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\specialcellbold}[2][b]{%
    \bfseries
    \sisetup{text-rm = \bfseries}%
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\leftspecialcell}[2][b]{%
    \begin{tabular}[#1]{@{}l@{}}#2\end{tabular}%
}

%Package for labelling matrix rows and columns
\RequirePackage{blkarray}

% Package to adjust labelled matrices
\RequirePackage{makebox,bigstrut,relsize}

% Page configuration
\RequirePackage{geometry}
\geometry{a4paper,hscale=0.75,vscale=0.8}

%Package to modify chapter header
%\RequirePackage{titlesec}
%Color for sections head
\RequirePackage{color}
\definecolor{tdblue}{RGB}{0,174,239}
\RequirePackage{sectsty}
\sectionfont{\color{tdblue}}
\subsectionfont{\color{tdblue}}
\subsubsectionfont{\color{tdblue}}
\paragraphfont{\color{tdblue}}

%MATLAB command
\RequirePackage{xspace}
\newcommand{\MATLAB}{\textsc{Matlab}\xspace}

%Typesetting a MATLAB code
\RequirePackage[T1]{fontenc}
\RequirePackage{bigfoot} % to allow verbatim in footnote
\RequirePackage[numbered,framed]{matlab-prettifier}
\RequirePackage{filecontents}
\let\ph\mlplaceholder % shorter macro
\lstMakeShortInline"
\lstset{
    style              = Matlab-editor,
    basicstyle         = \mlttfamily,
    escapechar         = ",
    mlshowsectionrules = true,
}

% Per-section figure, equation, table and lstlisting numbering
\RequirePackage{chngcntr}
\counterwithin{figure}{section}
\counterwithin{equation}{section}
\counterwithin{table}{section}
\AtBeginDocument{\counterwithin{lstlisting}{section}}

% Package for references with numbers
\bibliographystyle{apsrev4-1}
\RequirePackage[numbers]{natbib}
\setcitestyle{numbers}


% Set graphics path
\graphicspath{{./figures/}}

%-------------- Define command for missing figures ------------
\let\StandardIncludeGraphics\includegraphics%
\renewcommand{\includegraphics}[2][]{%
    \IfFileExists{./figures/#2}{%
        \StandardIncludeGraphics[#1]{#2}%
    }{%
    \IfFileExists{#2}{%
        \StandardIncludeGraphics[#1]{#2}%
    }{%
    \StandardIncludeGraphics[#1]{example-image-a}}}%
}% End of command

%-------------------- Report information ----------------------

\newcommand{\coursecode}[1]{\renewcommand{\coursecode}{#1}}
\newcommand{\coursename}[1]{\renewcommand{\coursename}{#1}}
\newcommand{\instructorname}[1]{\renewcommand{\instructorname}{#1}}
\newcommand{\reporttitle}[1]{\renewcommand{\reporttitle}{#1}}
\newcommand{\reportauthor}[3]{\renewcommand{\reportauthor}{#1 {\scshape #2} \dots\dots {\bfseries #3}}}
\newcommand{\frontcoverpic}[1]{\renewcommand{\frontcoverpic}{\includegraphics[height=5cm]{#1}}}

\newcommand{\makemargins}{
\makenomenclature
\pagestyle{fancy}
\fancyheadoffset{1cm}
\setlength{\headheight}{2cm}
\lhead{\includegraphics[width=0.25\textwidth]{./logos/logo.pdf}} % Set image at top of the page
\rhead{\nouppercase{\leftmark}}
\rfoot{\thepage}
\cfoot{\textbf{\reporttitle}}
\lfoot{\coursecode}
}

\newcommand{\makecoverpage}{
\begin{titlepage}

    \centering % Center the content
    \includegraphics[width=0.4\textwidth]{./logos/logo_blue.pdf}\par\vspace{1cm} % Insert logo
    {\scshape\LARGE Delft University of Technology \par} % Name of the university
    \vspace{1cm} % Vertical space of 1.5 cm
    {\scshape\Large \coursename \\ \large \coursecode \\ \normalsize \instructorname \par}
    \vspace{0.5cm} % Vertical space of 1 cm
    \rule{\linewidth}{0.2 mm} \\[0.4 cm]
    {\huge\bfseries \reporttitle \par} \
    \rule{\linewidth}{0.2 mm} \\[1 cm]
    \vspace{0.5cm}
    \frontcoverpic\\[1.5 cm]
    \normalsize \reportauthor\\
    \vfill
    {\large \today\par} % Visualization of the date

\end{titlepage}
}

\newcommand{\initialise}{
    \makemargins
    \makecoverpage
    \tableofcontents
    \newpage
}

% Define newcommand for norm
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}

答案1

在对 OP 进行一些调试后,我发现使用“低级”\rightmark命令(参见fancyhdr 文档) 使一切正常运行。如果您想要精确编辑部分名称的显示方式,您可以编辑\sectionmark命令(参见代码)。

\newcommand{\makemargins}{
\makenomenclature
\pagestyle{fancy}
\fancyheadoffset{1cm}
\setlength{\headheight}{2cm}
\lhead{\includegraphics[width=0.2\textwidth]{./logos/logo.pdf}} % Set image at top of the page
% \renewcommand{\sectionmark}[1]{\markright{\thesection\ \ ##1}} % Change appearance of marks
\rhead{\nouppercase{\rightmark}} % Use \rightmark instead of \leftmark..
\rfoot{\thepage}
\cfoot{\textbf{\reporttitle}}
\lfoot{\coursecode}
}

相关内容