헤더에 장 이름을 표시하는 방법은 무엇입니까?

헤더에 장 이름을 표시하는 방법은 무엇입니까?

나는 다음과 같은 WME를 가지고 있습니다 :

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}


\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}


\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[OC]{\thechapter.\quad\chaptertitle}% Author on Odd page, Centred
  \fancyhead[EC]{\thechapter.\quad\chaptertitle}% Title on Even page, Centred
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\begin{document}

\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]

\end{document}

이 WME를 사용하면 헤더에 장 번호만 표시됩니다. 헤더에 장 이름을 표시하려면 어떻게 해야 합니까?

답변1

로 이 작업을 수행할 수 있습니다 \leftmark.

왼쪽 표시

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}


\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}


\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[OC]{\leftmark}% Author on Odd page, Centred
  \fancyhead[EC]{\leftmark}% Title on Even page, Centred
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\begin{document}

\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]

\end{document}

다음은 "CHAPTER"가 없는 버전입니다.

없이

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage[pagestyles]{titlesec}
\usepackage{lipsum}
\usepackage{fancyhdr}


\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}

\usepackage{expl3,xparse}
\ExplSyntaxOn
\cs_generate_variant:Nn \tl_set:Nn {Nx}
\NewDocumentCommand{\replace}{mmm}
 {
  \pintodoido_replace:nnn {#1} {#2} {#3}
 }

\tl_new:N \l_pintodoido_input_text_tl
\tl_new:N \l_pintodoido_search_tl
\tl_new:N \l_pintodoido_replace_tl

\cs_new_protected:Npn \pintodoido_replace:nnn #1 #2 #3
 {
  \tl_set:Nf \l_pintodoido_input_text_tl { #1 }
  \tl_set:Nn \l_pintodoido_search_tl { #2 }
  \tl_set:Nn \l_pintodoido_replace_tl { #3 }
  \regex_replace_all:nnN { \b\u{l_pintodoido_search_tl}\b } { \u{l_pintodoido_replace_tl} } \l_pintodoido_input_text_tl
  \tl_use:N \l_pintodoido_input_text_tl
 }
\ExplSyntaxOff

\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[OC]{\replace{\leftmark}{Chapter}{}}% Author on Odd page, Centred
  \fancyhead[EC]{\replace{\leftmark}{Chapter}{}}% Title on Even page, Centred
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\begin{document}

\pagestyle{mypagestyle}
\chapter{Introduction}
\lipsum[1-40]

\end{document}

답변2

당신이 사용할 수있는

\AtBeginDocument{%
    \renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}%
}

헤더 항목에서 챕터 이름을 제거합니다.

\documentclass[twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}

\usepackage{fancyhdr}
\AtBeginDocument{%
    \renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}%
}
\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyhead[C]{\leftmark}%
  \fancyfoot[C]{\thepage}%
  \renewcommand{\headrulewidth}{.4pt}% Header rule of .4pt
}
\pagestyle{mypagestyle}

\usepackage{lipsum}% for dummy text
\begin{document}
\chapter{Introduction}
\lipsum[1-40]
\end{document}

여기에 이미지 설명을 입력하세요

또는 추가 페이지 스타일이 필요하지 않고 다음 fancy스타일을 사용할 수도 있습니다.

\documentclass[twoside]{book}

\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,headheight=28pt,bindingoffset=6mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[display]
  {\normalfont\bfseries}{}{10pt}{\Huge\thechapter.\quad}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\quad#1}{}}
\fancyhf{}% Clear header/footer
\fancyhead[C]{\leftmark}%
\fancyfoot[C]{\thepage}%

\usepackage{lipsum}% for dummy text
\begin{document}
\chapter{Introduction}
\lipsum[1-40]
\end{document}

결과는 위와 같습니다.

관련 정보