
我的目標是實現一本書的這種佈局(可能使用 fancyhdr,但我對一切都持開放態度):
當前佈局以灰色表示。換句話說,我想要:
- 將頁碼放在每頁的頁腳(部分標題頁除外)
- 將目前部分的名稱放在偶數(非特殊)頁上(格式如圖:PART I: XXX)+其下一行
- 將目前章節的名稱放在奇數(非特殊)頁上(格式如圖:第一章:XXX)+其下一行
我所說的「特殊頁面」是指章節標題的頁面或每章的首頁。
- 怎麼做?
- 從專業編輯的角度來看,偶數頁的頁首(左/中/右的部分標題?)和奇數頁的頁眉(左/中/右的章節標題?)應該選擇什麼對齊方式?喜歡/更“自然”的對齊方式?
這是一個基本文件的範例:
\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{hyperref}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
%Note: this is a very preliminary attempt...,
%Fancier solutions are welcome
%The page numbering does not work correctly
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE]{\thepart} %How do I get the part name in capital letters
\fancyhead[RO]{\thechapter} %How do I get the chapter name in capital letters
\begin{document}
\mainmatter
\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}
答案1
你可以嘗試使用
\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{hyperref}
\usepackage[head=15pt, top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{lipsum}
\newcommand*\parttitle{}
\let\origpart\part
\renewcommand*{\part}[2][]{%
\ifx\\#1\\% optional argument not present?
\origpart{#2}%
\renewcommand*\parttitle{#2}%
\else
\origpart[#1]{#2}%
\renewcommand*\parttitle{#1}%
\fi
}
\usepackage{fancyhdr}\pagestyle{fancy}
\fancyhead{}
\fancyhead[RO]{\leftmark}
\fancyhead[LE]{Partie \thepart: \parttitle}
\fancyfoot{}
\fancyfoot[C]{\thepage}
\begin{document}
\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}
\fancyhead[RO]{\leftmark}
您必須在和中編輯字體樣式\fancyhead[LE]{Partie \thepart: \parttitle}
。此外,您可能需要\thispagestyle{empty}
在新章節和新部分之前使用白頁。
我%
之前提出\usepackage[T1]{fontenc}
了線上乳膠編譯器的問題。也
答案2
下面將按照您所說的進行操作。我不確定這是否是您想要的,但您的里程可能會有所不同。
\pagestyle{fancy}
\fancyhf{}
\fancyhf[coh]{\rightmark}
\fancyhf[ceh]{\leftmark}
\fancyhf[cf]{\thepage}
\renewcommand\chaptermark[1]{\markright{\MakeUppercase{\chaptername{} \thechapter: #1}}}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{\MakeUppercase{\partname{} \thepart: #1}}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\makeatother
完整程式碼:
\documentclass[11pt,a4paper,french]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[coh]{\rightmark}
\fancyhf[ceh]{\leftmark}
\fancyhf[cf]{\thepage}
\renewcommand\chaptermark[1]{\markright{\MakeUppercase{\chaptername{} \thechapter: #1}}}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
\else
\addcontentsline{toc}{part}{#1}%
\fi
\markboth{\MakeUppercase{\partname{} \thepart: #1}}{}%
{\centering
\interlinepenalty \@M
\normalfont
\ifnum \c@secnumdepth >-2\relax
\huge\bfseries \partname\nobreakspace\thepart
\par
\vskip 20\p@
\fi
\Huge \bfseries #2\par}%
\@endpart}
\makeatother
\begin{document}
\mainmatter
\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}
編輯
我不確定上面的內容是否是您想要的原因是因為我認為當章節之間有空白頁時它看起來很奇怪。您可能不同意,但如果不同意,您可以根據需要消除它們。
如果您不想在章節之間的頁面上添加標題,但確實想要頁碼,請添加
\usepackage{etoolbox,nextpage}
\patchcmd{\chapter}{\cleardoublepage}{\cleartooddpage[\thispagestyle{plain}]}{\typeout{Chapters successfully patched for no headers on pages between chapters.}}{\typeout{Could not patch chapters to eliminate headers on pages between chapters.}}
如果您也不需要頁碼,請變更plain
為empty
。
順便說一句,我個人的觀點是這些標題太重並且分散注意力。在所有首都和中心,它們都帶有下劃線。我會推薦一種更微妙的方法,它可以在不將注意力從文字內容移開的情況下提供資訊。 (刪除規則或將標題移至一側或另一側並去掉大寫字母或......)
答案3
您可以修補\part
問題,\partmark
而\markboth{}{}
不是像\chapter
問題一樣\chaptermark
。然後只需適當定義這兩個巨集即可。
\documentclass[11pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage[top=1in, bottom=1in, left=1in, right=1in, headheight=13.6pt]{geometry}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage{lipsum}
%Note: this is a very preliminary attempt...,
%Fancier solutions are welcome
%The page numbering does not work correctly
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\begingroup\lccode`~=`:
\lowercase{\endgroup
\newcommand{\partmark}[1]{%
\markboth{\MakeUppercase{\partname\space\thepart~ #1}}{}%
}
\renewcommand{\chaptermark}[1]{%
\markright{\MakeUppercase{\chaptername\space\thechapter~ #1}}%
}
}% end of \lowercase
\makeatletter
\patchcmd{\H@old@part}% would be \@part without hyperref
{\markboth{}{}}
{\partmark{#1}}
{}{}
\makeatother
\begin{document}
\mainmatter
\part{Premiere partie}
\chapter{Premier chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Second chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\part{Deuxieme partie}
\chapter{Troisieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\chapter{Quatrieme chapitre}
\lipsum
\lipsum
\lipsum
\lipsum
\end{document}
請注意,為了在標題中獲取法式冒號,需要一個特殊的技巧。基本上,\partmark
和\chaptermark
是用冒號的活動版本定義的。
由於我們在加載後進行修補hyperref
,因此我們需要修補\H@old@part
而不是`\@part。
不要忽視fancyhdr
關於頭高的警告;我將建議的設定添加到 的選項中geometry
。