使用 quotchap 包将所有章节和附录标签和编号与右边距对齐

使用 quotchap 包将所有章节和附录标签和编号与右边距对齐

问题描述

我在将章节和附录标签和编号与右边距正确对齐时遇到问题。在下图中(仅是示例和我所面临的问题的表示),可以看到章节名称(贝克尔) 与右边距正确对齐(由黑色垂直线表示)。但是,章节标签和编号 (第1章) 没有与右边距对齐,如下图所示,蓝线(我为说明问题而添加的蓝色垂直线)和右边距(黑色垂直线所示)之间的空间/间隙就是明证。
问题描述
我需要帮助,了解如何将章节标签和编号与右边距对齐,以及章节名称。下面是我的 MWE,这是我之前遇到的问题的解决方案,@Simon Dispa (https://tex.stackexchange.com/users/161015/simon-dispa)帮助我使用 quotchap 包在章节号前添加单词“Chapter”

\documentclass[11pt,openany,twoside]{book}  
\usepackage[T1]{fontenc}% added <<<<<<
\raggedbottom
\let\cleardoublepage=\clearpage
\usepackage[left=2.5cm, right=2.5cm, top=3cm, bottom=3cm,a4paper]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage[dotinlabels]{titletoc}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline}
\pagestyle{fancy} 
\usepackage[noindentafter,calcwidth]{titlesec}
\usepackage[courier]{quotchap}
\usepackage{helvet}
\renewcommand\sectfont{\bfseries}
\usepackage{calc,pifont} 
\usepackage{multirow}
\newcommand*\myheaderfooterfont{\normalfont\bfseries}
\usepackage[nottoc]{tocbibind}
\usepackage[ragged]{sidecap}
\usepackage[marginal]{footmisc}
\renewcommand\footnoterule{\vspace*{-3pt}%
    \hrule width 2in height 1.4pt \vspace*{2.6pt}}
\setlength\footnotemargin{10pt}
\usepackage{etoolbox}
\usepackage{regexpatch}
\usepackage{listings}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
}
\usepackage[toc,header]{appendix}
\usepackage{apptools}   

\usepackage{showframe}

%************************************************** added
\usepackage{xstring}

\makeatletter       
    \patchcmd{\@makechapterhead}{\thechapter}{%
     \IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{\thechapter}{\appname\,\thechapter}{\chapname\,\thechapter}
    }           
\makeatother    

\newcommand{\appname}{{\fontfamily{phv}\fontsize{22pt}{26pt}\selectfont\raisebox{1em}{\textcolor{red}{Appendix}}}} % set the appendix name <<<<<<<<<<<
\newcommand{\chapname}{{\fontfamily{phv}\fontsize{22pt}{26pt}\selectfont\raisebox{1em}{\textcolor{red}{\chaptername}}}} % set the chapter name <<<<<<<<<<<
%************************************************** 

\begin{document} 
    \frontmatter
    \chapter*{Ac}
    \addcontentsline{toc}{chapter}{Ac}
    
    \mainmatter
    \setcounter{tocdepth}{1}
    \chapter{Backrre}
    \setcounter{chapter}{14}
    \chapter{Another chapter with \#15}

    \begin{appendices}
        \chapter{Derivation of X}
        The contents...
        \chapter{Derivation of Y}
        Another content...
        \setcounter{chapter}{15}
        \chapter{Derivation of P}
        \setcounter{chapter}{25}
        \chapter{Derivation of Z}
        Another content...      
    \end{appendices}
    
\end{document}

答案1

此解决方案适用于xelatex抑制章节编号的右侧边界。

例如侧边距和精确左/右对齐

A

b

C

d

% !TeX TS-program = xelatex

\documentclass[11pt,openany,twoside]{book}  

\raggedbottom
\let\cleardoublepage=\clearpage
\usepackage[left=2.5cm, right=2.5cm, top=3cm, bottom=3cm,a4paper]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[table]{xcolor}
\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}
\usepackage[dotinlabels]{titletoc}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{fancyhdr}
\usepackage{hhline}
\pagestyle{fancy} 
\usepackage[noindentafter,calcwidth]{titlesec}
\usepackage[courier]{quotchap}
\usepackage{helvet}
\renewcommand\sectfont{\bfseries}
\usepackage{calc,pifont} 
\usepackage{multirow}
\newcommand*\myheaderfooterfont{\normalfont\bfseries}
\usepackage[nottoc]{tocbibind}
\usepackage[ragged]{sidecap}
\usepackage[marginal]{footmisc}
\renewcommand\footnoterule{\vspace*{-3pt}%
\hrule width 2in height 1.4pt \vspace*{2.6pt}}
\setlength\footnotemargin{10pt}
\usepackage{etoolbox}
\usepackage{regexpatch}
\usepackage{listings}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
}
\usepackage[toc,header]{appendix}
\usepackage{apptools}   

\usepackage{showframe}

%************************************************** added 
\usepackage{fontspec}% added
\newfontfamily\NCourier[Mapping=tex-text]{Courier New} %
\usepackage{xstring}
\newcommand\ClipR[1]{% 
    \StrRight{#1}{1}[\tempii]%
    #1\kern-\XeTeXglyphbounds3 \the\XeTeXcharglyph\expandafter`\tempii% 
    }

\renewcommand*{\chapnumfont}{\NCourier\fontsize{100}{130}\selectfont\color{chaptergrey}}

\makeatletter 
\patchcmd{\@makechapterhead}{\thechapter}{%     
\StrRight{\thechapter}{1}[\tempii]
\IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{\thechapter}{\appname\,\ClipR{\thechapter}}{\chapname\,\ClipR{\thechapter}}
}        
\makeatother  

\newcommand{\appname}{{\fontencoding{T1}\fontfamily{phv}\fontsize{22pt}{26pt}\selectfont\raisebox{1em}{\textcolor{red}{Appendix}}}} % set the appendix name <<<<<<<<<<<
\newcommand{\chapname}{{\fontencoding{T1}\fontfamily{phv}\fontsize{22pt}{26pt}\selectfont\raisebox{1em}{\textcolor{red}{\chaptername}}}} % set the chapter name <<<<<<<<<<<
%************************************************** 

\begin{document} 

    \frontmatter
    \chapter*{Ac}
    \addcontentsline{toc}{chapter}{Ac}
    
    \mainmatter
    \setcounter{tocdepth}{1}
    \chapter{ONE}   
    \chapter{TWO}
    \chapter{THREE}
    \chapter{FOUR}
    \chapter{FIVE}
    \chapter{SIX}
    \chapter{SEVEN}
    \chapter{EIGHT}
    \chapter{NINE}
    \chapter{TEN}
    
\begin{appendices}
    \chapter{Derivation of A}   
    \chapter{Derivation of B}   
    \chapter{Derivation of C}
    \chapter{Derivation of D}    
    \chapter{Derivation of E}   
    \chapter{Derivation of F}
    \chapter{Derivation of G}   
    \chapter{Derivation of H}   
    \chapter{Derivation of I}   
    \chapter{Derivation of J}
    \chapter{Derivation of K}   
    \chapter{Derivation of L}   
    \chapter{Derivation of M}   
    \chapter{Derivation of N}
    \chapter{Derivation of O}   
    \chapter{Derivation of P}       
    \chapter{Derivation of Q}   
    \chapter{Derivation of R}
    \chapter{Derivation of S}   
    \chapter{Derivation of T}        
    \chapter{Derivation of U}   
    \chapter{Derivation of V}   
    \chapter{Derivation of W}   
    \chapter{Derivation of X}   
    \chapter{Derivation of Y}   
    \chapter{Derivation of Z}       
\end{appendices}
    
\end{document}

相关内容