0

Problem Description

I am having a problem with the right alignment of chapters and appendices labels and numbers to the right margin. In the picture below (just an example and a representation of the problem I am facing), it can be seen that the chapter name (Backrre) is properly aligned to the right margin (indicated by the black vertical line). However, the chapter label and number (Chapter 1) is not aligned to the right margin as can be seen by the space/gap between the blue line (the blue vertical line I added to illustrate my problem) and the right margin (shown by the black vertical line) in the picture below.
Problem description
I need assistance on how to align the chapters labels and numbers to the right margin as are the chapter names. Below is my MWE which was a solution to my previous problem that @Simon Dispa (https://tex.stackexchange.com/users/161015/simon-dispa) assisted me with at Adding the word "Chapter" before Chapter number using the quotchap package:

\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}

itc
  • 657

1 Answers1

1

This solution works with xelatex suppressing the right sidebearing of the chapter number.

For example see sidebearings and precision left/right alignment

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}

Simon Dispa
  • 39,141
  • Why are we now renewing the chapter number font? Isn't the command \usepackage[courier]{quotchap} enough? Is it possible that we do not renew the chapter number font such that we can set the font type through the quotchap package? Please help. – itc Jul 11 '22 at 18:45
  • 1
    @itc Both numbers and letters must be aligned to the right. This is done using xelatex to calculate the correction. quotchap needs pdflatex to change fonts, so to do this is not useful. Remember, one question at a time (font family). – Simon Dispa Jul 11 '22 at 21:46
  • 1
    @itc Please add a code example showing the issue on sections names and other font styles used in your document. – Simon Dispa Jul 12 '22 at 13:57
  • I have modified the code @Simon Dispa – itc Jul 12 '22 at 14:46
  • 1
    @itc Use \newenvironment{myfont1}{\fontencoding{T1}\fontfamily{pzc}\selectfont}{\par} \newenvironment{myfont2}{\fontencoding{T1}\fontfamily{phv}\selectfont}{\par} (and compile with xelatex!) – Simon Dispa Jul 12 '22 at 15:20
  • @itc \sfdefault is set by \usepackage{helvet} to phv – Simon Dispa Jul 12 '22 at 16:41
  • @itc \normalfont\bfseries\sffamily is fine. I do not understand your question. In your last example section titles are bold + helvetica. – Simon Dispa Jul 12 '22 at 17:10