我有以下代码来定义一本书的风格,但我遇到了三个问题。
第一,目录中的页数不正确
第二,我想在页眉中显示章节所属偶数页的部分的标题。在第 8 页上,我以第 2 部分的标题作为页眉,但它属于第 1 部分。
3、目录的标题应为“Índice”而不是“INDICE”。
提前致谢,
\documentclass{book}
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{emptypage}
\usepackage[labelsep=period]{caption}
\setcounter{secnumdepth}{3} %Niveles de titulos
\setcounter{tocdepth}{2} %Niveles en TOC
\usepackage[paperwidth = 17cm,paperheight = 24cm]{geometry}
\usepackage{lipsum}
\usepackage{xparse}
\newcommand{\originalpart}{} % trigger an error if already defined
\newcommand{\parttitle}{}
\let\originalpart\part
\RenewDocumentCommand{\part}{som}{%
\IfBooleanTF{#1}
{% \part*
\IfNoValueTF{#2}
{\renewcommand\parttitle{#3}}
{\renewcommand\parttitle{#2}}%
\originalpart*{#3}
}%
{% normal \part
\IfNoValueTF{#2}
{\renewcommand\parttitle{#3}\originalpart{#3}}
{\renewcommand\parttitle{#2}\originalpart[#2]{#3}}%
}%
}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO]{\leftmark}
\fancyhead[LE]{\parttitle}
\fancyfoot[LE]{ \thepage}
\fancyfoot[RO]{ \thepage}
\fancypagestyle{plain}{%
\fancyhead{}% no header
\renewcommand{\headrule}{}% no header rule
% footer is "inherited" from fancy
\renewcommand{\headrulewidth}{0pt}%
\fancyhf{}%
}
\addto\captionsspanish{
\renewcommand{\contentsname}%
{Índice}%
}
\renewcommand{\chaptermark}[1]{%
\markboth{\chaptername
\ \thechapter.\ #1}{}}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{2}
\usepackage[a4, center, cross, noinfo]{crop}
\begin{document}
\tableofcontents
\part[Short title of part1]
{Long title of part1}
\chapter[Title of chapter1]
{Long title of chapter} \lipsum[2-17]
\part[Short title of part2]
{Long title of part2}
\chapter[Title of chapter2]
{Long title of chapter} \lipsum[2-20]
\addcontentsline{toc}{chapter}{Appendix}\chapter*{Appendix} \lipsum[2-20]
\end{document}
答案1
部分答案。下面是您的 MWE 的修订版,它几乎满足了您的要求,但在标题中固定了部分标题文本。我没有对打印为 Indice 的 ToC 标题进行任何处理。
% bookheadtocprob.tex SE 602257
\documentclass{book}
\usepackage{comment}
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usepackage{fancyhdr}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{emptypage}
\usepackage[labelsep=period]{caption}
\setcounter{secnumdepth}{3} %Niveles de titulos
\setcounter{tocdepth}{2} %Niveles en TOC
\usepackage[paperwidth = 17cm,paperheight = 24cm]{geometry}
\usepackage{lipsum}
\usepackage{xparse}
\begin{comment}
%%% I don't understand this
\newcommand{\originalpart}{} % trigger an error if already defined
\newcommand{\parttitle}{}
\let\originalpart\part
\RenewDocumentCommand{\part}{som}{%
\IfBooleanTF{#1}
{% \part*
\IfNoValueTF{#2}
{\renewcommand\parttitle{#3}}
{\renewcommand\parttitle{#2}}%
\originalpart*{#3}
}%
{% normal \part
\IfNoValueTF{#2}
{\renewcommand\parttitle{#3}\originalpart{#3}}
{\renewcommand\parttitle{#2}\originalpart[#2]{#3}}%
}%
}
\end{comment}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[RO]{\leftmark}
%\fancyhead[LE]{\parttitle}
%\fancyhead[LE]{\the\part parttitle}
\fancyhead[LE]{Parttitle \thepart} %% just to show the Part number
\fancyfoot[LE]{ \thepage \hspace{0.5cm} $\copyright$ Ediciones Paraninfo}
\fancyfoot[RO]{ $\copyright$ Ediciones Paraninfo \hspace{0.5cm} \thepage}
\fancypagestyle{plain}{%
\fancyhead{}% no header
\renewcommand{\headrule}{}% no header rule
% footer is "inherited" from fancy
\renewcommand{\headrulewidth}{0pt}%
\fancyhf{}%
}
\addto\captionsspanish{
\renewcommand{\contentsname}%
{Índice}%
}
\renewcommand{\chaptermark}[1]{%
\markboth{\chaptername
\ \thechapter.\ #1}{}}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{2}
\usepackage[a4, center, cross, noinfo]{crop}
\begin{document}
\tableofcontents
\part[Short title of part1]
{Long title of part1}
\chapter[Title of chapter1]
{Long title of chapter} \lipsum[2-17]
\part[Short title of part2]
{Long title of part2}
\chapter[Title of chapter2]
{Long title of chapter} \lipsum[2-20]
%%%% wrong order
% \addcontentsline{toc}{chapter}{Appendix}\chapter*{Appendix} \lipsum[2-20]
\chapter*{Appendix} \addcontentsline{toc}{chapter}{Appendix} \lipsum[2-20]
\end{document}
请注意,附录中的页眉引用了上一章,因此您可能需要对此进行一些处理。我认为您的重新定义存在问题,\part
我对此并不理解,因此我将其注释掉,并将部分页眉放在了相应的页面上。
答案2
第二个问题已经解决,添加\newpage
之前\part