2

I am using the following MWE. I want to define a chapter, with different sections (Prologue, paper 1, paper 2). I want the star marked sections to show up in TOC, for which I am using a user defined command.

However, I see that the page header, does not get updated. I want the page header to be the same as the star marked section or subsection. enter image description here Can you please help?

\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}
3
  • hi @moewe, here is the MWE of the problem. Can you help?
    – Rouge
    Dec 3, 2018 at 9:38
  • Would it not make more sense to have the header read "Paper I" or "Paper II"?
    – moewe
    Dec 3, 2018 at 9:42
  • 1
    For reference, the \tocsection came from tex.stackexchange.com/q/453071/35864. The idea was actually that you'd just write \tocsection{Paper I} and \tocsection{Paper II} in your document and not the entire complicated definition \refstepcounter{section}....
    – moewe
    Dec 3, 2018 at 9:45

1 Answer 1

3

You need also a \sectionmark command if you want to update the headers:

\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}

enter image description here

2
  • May I suggest incorporating \sectionmark into \tocsection and using that instead of the bare definition of the command. (I know the MWE didn't do that, but it was definitely the intention in the linked answer.)
    – moewe
    Dec 3, 2018 at 14:06
  • Thanks a lot @moewe, it works... Just one last question. can you please how can force lower case word in "Paper I" : I want to write a chemical formula eg Gd2O3. 'd' should be lower case
    – Rouge
    Dec 3, 2018 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .