1

I am using the book class for my document. The current version displays the title of the chapter in even pages and the subsection name in odd pages. I want to display the chapter name and number in even and odd pages. What do I have to change in the code below:

\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}} 
1
  • 1
    Welcome to TeX.se! Please extend your code fragment to complete small document which we can test as it is.
    – Zarko
    Sep 1, 2022 at 14:53

1 Answer 1

0

This way

\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ \textcolor{red}{#1}}{\thechapter.\ \textcolor{red}{#1}}} 
\renewcommand*\sectionmark[1]{} 

a

Try this code:

\documentclass{book}

\usepackage{kantlipsum}% dummy text
\usepackage{xcolor}

%****************************** added <<<<<<<<
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ \textcolor{red}{#1}}{\thechapter.\ \textcolor{red}{#1}}} 
\renewcommand*\sectionmark[1]{} 
%******************************

\begin{document}

    \chapter{ONE}
        \kant[1-4]
    
    \section{First sec}
        \kant[1-4]
    
    \section{Second sec}
        \kant[1-4]
        
    \chapter*{TWO}
    \markboth{\textcolor{red}{TWO}}{\textcolor{red}{TWO}} % add the marks
    
        \kant[1-4]
        
        \section{First sec}
        \kant[1-4]
        
        \section{Second sec}
        \kant[1-4]

\end{document}

Unnumbered (starred) sectional units do not update the marks (in the book class) but you can add them the manually.

1
  • Thanks a lot this is the answer! This are the changes I did to the two lines of code I have: \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ \color{title}{#1}}{\thechapter.\ \color{title}{#1}}} \renewcommand*\sectionmark[1]{} Sep 2, 2022 at 6:28

You must log in to answer this question.

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