我使用了 titlesec 包和 geometry 包来获得以下章节样式(请注意,我使用的是 XeLaTeX):
这可行,但是我无法按我想要的方式对齐章节编号。此外,具有两个编号的章节超出了页面边界:
这就是我想要的格式:
章节编号应与标题规则右对齐。这是现在的 MWE:
\documentclass[twoside,a4paper,11pt,fleqn,openright]{report}
\usepackage{lipsum}
\usepackage{subfiles}
\usepackage{ifxetex,ifluatex}
% Fonts
\usepackage{mathspec}
\makeatletter % undo the wrong changes made by mathspec
\let\RequirePackage\original@RequirePackage
\let\usepackage\RequirePackage
\makeatother
\ifdefined\suppressfontnotfounderror
\expandafter\let\csname xetex_suppressfontnotfounderror:D\endcsname
\suppressfontnotfounderror
\else
\expandafter\let\csname xetex_suppressfontnotfounderror:D\endcsname
\luatexsuppressfontnotfounderror
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle,Scale=MatchLowercase}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmonofont[Mapping=tex-ansi,Path=../fonts/,UprightFont=InconsolataRegular.ttf,BoldFont=InconsolataBold.ttf]{InconsolataRegular.ttf}
\setmathfont[math-style=ISO, bold-style=ISO]{TeX Gyre Pagella Math}
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\usepackage[final=true]{microtype}
\microtypecontext{spacing=french}
\UseMicrotypeSet[protrusion]{basicmath}
\usepackage[a4paper,includeheadfoot,margin=2.5cm]{geometry}
\usepackage{xcolor}
\definecolor{mydarkestpurple}{rgb}{0.18,0.035,0.38}
\def\myrulewidth{0.4mm}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]%
{\relax}{\mbox{}\marginpar{\vspace*{-\baselineskip}\color{mydarkestpurple}\fontsize{78}{94}\selectfont\thechapter}}{0pt}%
{\Huge\bfseries\color{mydarkestpurple} #1}[\normalsize\vspace*{.8\baselineskip}\titleline{\color{mydarkestpurple}\titlerule}]%
\titlespacing*{\chapter}{0pt}{0cm}{1cm}
\begin{document}
\chapter{One}
\lipsum[1]
\setcounter{chapter}{9}
\chapter{Ten}
\lipsum[2]
\end{document}
有人可以帮忙吗?
答案1
这是可以满足您的要求的代码。您确实不希望章节编号位于页边距中,而是位于右页边距的左侧,因此我使用了\filleft
titlesec 中的命令。
我不得不删除该路径Inconsolata
(我没有该路径;我用 MiKTeX 附带的版本替换了它,并且它在路径中)。
\documentclass[twoside,a4paper,11pt,fleqn,openright]{report}
\usepackage{lipsum}
\usepackage{subfiles}
\usepackage{ifxetex,ifluatex}
% Fonts
\usepackage{mathspec}
\makeatletter % undo the wrong changes made by mathspec
\let\RequirePackage\original@RequirePackage
\let\usepackage\RequirePackage
\makeatother
\ifdefined\suppressfontnotfounderror
\expandafter\let\csname xetex_suppressfontnotfounderror:D\endcsname
\suppressfontnotfounderror
\else
\expandafter\let\csname xetex_suppressfontnotfounderror:D\endcsname
\luatexsuppressfontnotfounderror
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle,Scale=MatchLowercase}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmonofont[Mapping=tex-ansi,UprightFont=Inconsolatazi4-Regular.otf,BoldFont=Inconsolatazi4-Bold.otf]{InconsolataRegular.ttf}
\setmathfont[math-style=ISO, bold-style=ISO]{TeX Gyre Pagella Math}
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\usepackage[final=true]{microtype}
\microtypecontext{spacing=french}
\UseMicrotypeSet[protrusion]{basicmath}
\usepackage[a4paper,includeheadfoot,margin=2.5cm]{geometry}
\usepackage{xcolor}
\definecolor{mydarkestpurple}{rgb}{0.18,0.035,0.38}
\def\myrulewidth{0.6mm}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[block]%
{\color{mydarkestpurple}}{}{0pt}%
{\parbox[b]{0.75\textwidth}{\Huge\bfseries#1}\hfill \fontsize{78}{94}\selectfont\thechapter}[\normalsize\vspace*{.8\baselineskip}{\titlerule[\myrulewidth]}]%
\titlespacing*{\chapter}{0pt}{0cm}{1cm}
\begin{document}
\chapter{One }
\lipsum[1]
\setcounter{chapter}{9}
\chapter{Ten.\\ Tweedledum And Tweedledee}
\lipsum[2]
\end{document}