我们可以将未编号章节的标题添加到页眉吗?

我们可以将未编号章节的标题添加到页眉吗?

我想在章节序言的页眉中添加“PREFACE”。由于序言是无编号章节,因此无法在页眉中显示。如何显示它?

\documentclass[a4paper,twoside,12pt]{book}
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}

\titleformat{\chapter}
[display]
{\center\bfseries}
{\large\MakeUppercase{\chaptertitlename} \thechapter}{0cm}{\large}
\titlespacing{\chapter}{0cm}{-1cm}{0.5cm}
%\usepackage[utf8]{inputenc}
\titleformat{\section}
[hang]
{\bfseries}
{\bfseries\thesection}{1ex}{\bfseries}
%\titlespacing{\section}{1.5pt}{0.2cm}{-0.2cm}

\titleformat{\subsection}
[hang]
{\bfseries}
{\bfseries\thesubsection}{1ex}{\bfseries}
%\titlespacing{\subsection}{0cm}{3ex}{0ex}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thesubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE,LO]{\leftmark}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{\textbf{{\footnotesize Ongky Denny Wijaya}}}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}
\fancypagestyle{plain}{%
    \fancyhf{}%
    \fancyhead[LE,RO]{\thepage}%
    \fancyhead[RE,LO]{\leftmark}
    \fancyfoot[CE,CO]{}
    \fancyfoot[LE,RO]{\textbf{{\footnotesize Ongky Denny Wijaya}}}
}
\begin{document}
    \frontmatter
    \chapter*{PREFACE}
    ABC
    \mainmatter
    \chapter{TEST}

在此处输入图片描述

答案1

手动添加\markboth{PREFACE}{}

\documentclass[a4paper,twoside,12pt]{book}
\usepackage[left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}

\titleformat{\chapter}
[display]
{\center\bfseries}
{\large\MakeUppercase{\chaptertitlename} \thechapter}{0cm}{\large}
\titlespacing{\chapter}{0cm}{-1cm}{0.5cm}
%\usepackage[utf8]{inputenc}
\titleformat{\section}
[hang]
{\bfseries}
{\bfseries\thesection}{1ex}{\bfseries}
%\titlespacing{\section}{1.5pt}{0.2cm}{-0.2cm}

\titleformat{\subsection}
[hang]
{\bfseries}
{\bfseries\thesubsection}{1ex}{\bfseries}
%\titlespacing{\subsection}{0cm}{3ex}{0ex}

\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thesubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE,LO]{\leftmark}
\fancyfoot[CE,CO]{}
\fancyfoot[LE,RO]{\textbf{{\footnotesize Ongky Denny Wijaya}}}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{1pt}
\fancypagestyle{plain}{%
    \fancyhf{}%
    \fancyhead[LE,RO]{\thepage}%
    \fancyhead[RE,LO]{\leftmark}
    \fancyfoot[CE,CO]{}
    \fancyfoot[LE,RO]{\textbf{{\footnotesize Ongky Denny Wijaya}}}
}
\begin{document}
    \frontmatter
    \chapter*{PREFACE}
    \markboth{PREFACE}{}
    ABC
    \mainmatter
    \chapter{TEST}

\end{document}

相关内容