客观的: 我需要获取左上角左侧偶数页(LE)的页码:当页眉包含多行时,此方法会失败(然后将其打印在第二行)。
当我添加\parbox[t]
后\thepage
,页码位于左上角(第一行)。但是,我收到新的错误,并且当标题只有一行时,它会将文本向下移动一行。输出可以在此处查看:
https://ibb.co/ZX280PM
错误:
@iiiparbox 的参数有一个额外的}。
我正在使用在线脚本(免费提供)(请注意,这是我添加 \parbox[t] 的地方)。这是其中的一部分:
\fancypagestyle{mainmatter}{%
\fancyhf{}
%% Page numbers on the top left and top right.
\fancyhead[LE]{\cropmarks\lthumb\titlefont\thepage{\parbox[t]}}
\fancyhead[RO]{\cropmarks\rthumb\titlefont\thepage}
%% Chapter name on the left (even) page.
\fancyhead[RE]{\titlefont\titleshape\nouppercase{\leftmark}}
%% Section name on the right (odd) page.
\fancyhead[LO]{\titlefont\titleshape\nouppercase{\rightmark}}
}
我的论文.cls:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{dissertation}[2013/07/08 v1.0 TU Delft dissertation class]
\newif\if@nativefonts
\DeclareOption{nativefonts}{\@nativefontstrue}
\newif\if@print
\DeclareOption{print}{\@printtrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions\relax
\LoadClass[10pt]{book}
\RequirePackage{amsmath}
\RequirePackage{amssymb}
%% English is the default language, but Dutch is used for some sections.
\RequirePackage[dutch,english]{babel}
\RequirePackage{calc}
\RequirePackage[nooneline,footnotesize]{caption}
\RequirePackage{chapterbib}
\RequirePackage{etaremune}
\RequirePackage{fancyhdr}
\RequirePackage[flushmargin,hang]{footmisc}
\RequirePackage{ifpdf}
\RequirePackage{ifxetex}
\ifxetex
\RequirePackage[xetex]{geometry}
\RequirePackage[xetex]{graphicx}
\RequirePackage[xetex]{hyperref}
\RequirePackage{fontspec}
\RequirePackage{xltxtra}
\defaultfontfeatures{Ligatures=TeX}
\else
\ifpdf
\RequirePackage[pdftex]{geometry}
\RequirePackage[pdftex]{graphicx}
\RequirePackage[pdftex]{hyperref}
\else
\RequirePackage[dvips]{geometry}
\RequirePackage[dvips]{graphicx}
\RequirePackage[hypertex]{hyperref}
\fi
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\fi
\RequirePackage{lettrine}
\RequirePackage{metalogo}
\RequirePackage[sectionbib,numbers,sort&compress]{natbib}
\RequirePackage{tikz}
\RequirePackage[noindentafter]{titlesec}
\RequirePackage{titletoc}
\RequirePackage[nottoc]{tocbibind}
\RequirePackage{xcolor}
\RequirePackage{wrapfig}
\RequirePackage{booktabs}
\RequirePackage[flushleft]{threeparttable}
\RequirePackage{adjustbox}
\RequirePackage{bibentry}
\usepackage{float}
\RequirePackage{tabularx}
\usepackage{rotating}
\RequirePackage{lipsum}
%% If the document is not compiled with XeLaTeX, we need to use the native
%% fonts.
\ifxetex\else
\@nativefontstrue
\fi
\if@nativefonts
%% The native font is Utopia Regular with Fourier math. We use Latin Modern
%% as a fallback, since Utopia lacks support for sans-serif and monospace.
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{lmodern}
\RequirePackage{fourier}
%% The style for titles is small caps.
\def\titlefont{\rmfamily}
\def\titleshape{\scshape}
\def\titlestyle{\titlefont\titleshape\bfseries}
\if@print
\def\headerstyle{\titlefont\titleshape\bfseries}
\else
\def\headerstyle{\titlefont\titleshape}
\fi
\definecolor{wesandersonred}{cmyk}{0.00,0.90,0.86,0.29}
%% Set the paper size to 17 by 24 cm, approximately halfway between A4 and A5.
\if@print
%% In print mode we add a 3 mm bleed on the outside of the page.
\geometry{
papersize = {173mm,246mm},
layoutsize = {167mm,240mm},
layoutoffset = {3mm,3mm},
bindingoffset = -3mm
}
\else
\geometry{papersize={170mm,240mm}}
\fi
%% We decrease the margins slightly from the default (scale = 0.7).
\geometry{hscale=0.75,vscale=0.8}
%% Redefine the title command to accept an optional subtitle.
\renewcommand*\title[2][]{%
\def\@subtitle{#1}%
\def\@title{#2}%
%% Add the title to the PDF meta data.
\hypersetup{pdftitle=#2}%
}
%% Fancy style for the main matter.
\fancypagestyle{mainmatter}{%
\fancyhf{}
%% Page numbers on the top left and top right.
\fancyhead[LE]{\titlefont\thepage}
\fancyhead[RO]{\titlefont\thepage}
%% Chapter name on the left (even) page.
\fancyhead[RE]{\titlefont\titleshape\nouppercase{\leftmark}}
%% Section name on the right (odd) page.
\fancyhead[LO]{\titlefont\titleshape\nouppercase{\rightmark}}
}
%% The mainmatter style is default for normal pages.
\pagestyle{mainmatter}
%% Print the current chapter and section at the top of the page in cyan.
\renewcommand*\chaptermark[1]{\markboth{\color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}}
%% Change the headrule command (from fancyhdr.sty) to draw the line below the
%% header in the title color.
\renewcommand*\headrule{%
\if@fancyplain%
\let\headrulewidth\plainheadrulewidth%
\fi%
{\color{title}\hrule\@height\headrulewidth\@width\headwidth}%
\vskip-\headrulewidth%
}
我的论文.tex:
\documentclass{dissertation}
\begin{document}
\title[Test]{test}
\author{Author}{Name}
\mainmatter
\include{chapter-4}
\include{chapter-5}
\end{document}
第4章.tex:
\chapter[This header needs to be long to be a two line header header \\ header header header]{This header needs to be long to be a two line header}
\label{chapter_4}
\newpage
\lipsum[1]
第 5 章.tex:
\chapter[This header needs to be short to be a single line header ]{This header needs to be short}
\label{chapter_5}
\newpage
\lipsum[2]
有人能帮助我完成这个任务吗?
编辑:添加 .cls 和 .tex 示例
答案1
在 中dissertation.cls
,将所显示的页面样式替换为以下内容:
\fancypagestyle{mainmatter}{%
\fancyhf{}
\fancyhead[LE]{%
\titlefont{\parbox[b]{\headwidth}{%
\raggedleft\thepage\hfill\titleshape\nouppercase{\leftmark}}%
}%
}
\fancyhead[RO]{\titlefont\thepage}
\fancyhead[RE]{}
\fancyhead[LO]{\titlefont\titleshape\nouppercase{\rightmark}}
}
这将确保您的页码始终位于最左上角,与您的章节标题共享相同的基线(用于比较的虚线蓝线):
怎么运行的:
在这个新代码中,我不再为偶数页设置页眉左侧和页眉右侧,而是直接清空页眉右侧。在左侧,我构造一个与页眉宽度完全相同的框,并将所有内容移到右侧 ( \raggedleft
)。在第一行,我插入页码 ( \thepage
)、水平空格 ( \hfill
) 和连续章节标题 ( \leftmark
)。这样会形成明显的“左侧”和“右侧”,并确保页码和页眉的第一行始终在同一行。