如何更新标题和目录以标记星号部分

如何更新标题和目录以标记星号部分

我正在使用以下 MWE。我想定义一个包含不同部分(序言、论文 1、论文 2)的章节。我希望星号标记的部分显示在目录中,为此我使用了用户定义的命令。

但是,我发现页眉没有更新。我希望页眉与标有星号的部分或子部分相同。 在此处输入图片描述 你能帮忙吗?

\documentclass[british]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{fancyhdr}

\newcommand*{\tocsection}[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\rightmark}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\begin{document}
\tableofcontents

\chapter{Lorem}
\section{Prologue}
lorem ipsum

The name of this chapter is Lorem. It is chapter 1. This chapter has section called: paper 1, paper 2 and paper 3.

\newpage

\refstepcounter{section}\addcontentsline{toc}{section}{\protect\numberline{\thesection}Paper I}\label{Paper I}

The title of the paper I is defined as.
\begin{center}
        \begin{minipage}{10 cm}
            \huge Electrical Properties\\
        \end{minipage}
    \end{center}

This paper I, has lot of sections : Introduction, Methods, Results etc.

\subsection*{Introduction}
lorem ipsum dolor sit amet

\newpage

\refstepcounter{section}\addcontentsline{toc}{section}{\protect\numberline{\thesection}Paper II}\label{Paper II}

The title of the paper II is defined as.
\begin{center}
    \begin{minipage}{10 cm}
        \huge Optical Properties\\
    \end{minipage}
\end{center}

This paper II, also have a lot of sections : Introduction, Methods, Results etc.

\subsection*{Introduction}
lorem ipsum dolor sit amet

\end{document}

答案1

如果您想更新标题,您还需要一个 \sectionmark 命令:

\documentclass[british]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{fancyhdr}

\newcommand*{\tocsection}[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\rightmark}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\begin{document}
\tableofcontents

\chapter{Lorem}
\section{Prologue}
lorem ipsum

The name of this chapter is Lorem. It is chapter 1. This chapter has section called: paper 1, paper 2 and paper 3.

\newpage


\refstepcounter{section}%
\sectionmark{Paper 1}%
\addcontentsline{toc}{section}{\protect\numberline{\thesection}Paper I}\label{Paper I}

The title of the paper I is defined as.
\begin{center}
        \begin{minipage}{10 cm}
            \huge Electrical Properties\\
        \end{minipage}
    \end{center}

This paper I, has lot of sections : Introduction, Methods, Results etc.

\subsection*{Introduction}
lorem ipsum dolor sit amet

\newpage

\refstepcounter{section}%
\sectionmark{Paper 1}%
\addcontentsline{toc}{section}{\protect\numberline{\thesection}Paper II}\label{Paper II}

The title of the paper II is defined as.
\begin{center}
    \begin{minipage}{10 cm}
        \huge Optical Properties\\
    \end{minipage}
\end{center}

This paper II, also have a lot of sections : Introduction, Methods, Results etc.

\subsection*{Introduction}
lorem ipsum dolor sit amet

\end{document}

在此处输入图片描述

相关内容