mirror of
https://github.com/hendricius/the-sourdough-framework
synced 2025-11-25 04:21:11 -06:00
Change chapters heading (#173)
* Implement kaobook style chapter headings Now supports several style of chapters - plain (default koma) - bar adds a gray bar - lines (a box around it) - kao This is totally _inspired_ by the kaobook template: https://github.com/fmarotta/kaobook/ * Use lines style for chapter by default As Hendrik indicated...
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
\usepackage{makecell}
|
\usepackage{makecell}
|
||||||
\usepackage[mode=match, reset-text-family=false]{siunitx}
|
\usepackage[mode=match, reset-text-family=false]{siunitx}
|
||||||
\usepackage{fontspec}
|
\usepackage{fontspec}
|
||||||
|
\usepackage{calc}
|
||||||
|
|
||||||
\renewcommand\theadfont{\bfseries}
|
\renewcommand\theadfont{\bfseries}
|
||||||
|
|
||||||
@@ -75,5 +76,178 @@
|
|||||||
\usepackage{caption}
|
\usepackage{caption}
|
||||||
\captionsetup[figure]{font=footnotesize}
|
\captionsetup[figure]{font=footnotesize}
|
||||||
|
|
||||||
|
|
||||||
\DeclareSIUnit\degF{\text{°}F}
|
\DeclareSIUnit\degF{\text{°}F}
|
||||||
|
|
||||||
|
%-----------------------------------------------------------------------------
|
||||||
|
% KAO CHAPTER HEADING STYLES
|
||||||
|
%-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
\newlength{\hscale}
|
||||||
|
\newlength{\vscale}
|
||||||
|
\newlength{\mtocshift}
|
||||||
|
|
||||||
|
% By default, the scales are set to work for a4paper
|
||||||
|
\setlength{\hscale}{1mm}
|
||||||
|
\setlength{\vscale}{1mm}
|
||||||
|
|
||||||
|
\newif\ifwidelayout%
|
||||||
|
\def\IfWideLayout{%
|
||||||
|
\ifwidelayout%
|
||||||
|
\expandafter\@firstoftwo%
|
||||||
|
\else%
|
||||||
|
\expandafter\@secondoftwo%
|
||||||
|
\fi%
|
||||||
|
}
|
||||||
|
|
||||||
|
% Command to easily switch between chapter styles
|
||||||
|
\DeclareDocumentCommand{\setchapterstyle}{m}{%
|
||||||
|
\ifthenelse{\equal{plain}{#1}}{\chapterstyleplain}{}
|
||||||
|
\ifthenelse{\equal{bar}{#1}}{\chapterstylebar}{}
|
||||||
|
\ifthenelse{\equal{lines}{#1}}{\chapterstylelines}{}
|
||||||
|
\ifthenelse{\equal{kao}{#1}}{\chapterstylekao}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
% The default definition in KOMA script
|
||||||
|
\DeclareDocumentCommand{\chapterstyleplain}{}{%
|
||||||
|
\renewcommand{\chapterlinesformat}[3]{%
|
||||||
|
\@hangfrom{##2}{##3}}
|
||||||
|
\renewcommand*{\chapterformat}{%
|
||||||
|
\mbox{\chapappifchapterprefix{\nobreakspace}\thechapter%
|
||||||
|
\autodot\IfUsePrefixLine{}{\enskip}}}
|
||||||
|
\RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}
|
||||||
|
\setlength{\mtocshift}{-1\vscale}
|
||||||
|
}
|
||||||
|
|
||||||
|
% Gray bar
|
||||||
|
\DeclareDocumentCommand{\chapterstylebar}{}{%
|
||||||
|
\renewcommand*{\chapterformat}{%
|
||||||
|
\mbox{\chapappifchapterprefix{\nobreakspace}\thechapter%
|
||||||
|
\autodot\IfUsePrefixLine{}{\enskip}}%
|
||||||
|
}
|
||||||
|
\renewcommand{\chapterlinesformat}[3]{%
|
||||||
|
\begin{tikzpicture}[remember picture, overlay]
|
||||||
|
\node[
|
||||||
|
anchor=south west,
|
||||||
|
xshift=\dimexpr - \hoffset - \oddsidemargin - 1in -1mm,%-30\hscale,
|
||||||
|
yshift=4.3mm,
|
||||||
|
rectangle,
|
||||||
|
fill=gray!20!white,
|
||||||
|
fill opacity=0.8,
|
||||||
|
inner ysep=5\vscale,
|
||||||
|
inner xsep=\dimexpr \hoffset + \oddsidemargin + 1in,%30\hscale,
|
||||||
|
text opacity=1,
|
||||||
|
text width=\paperwidth-40\hscale,
|
||||||
|
]{\@hangfrom{##2}{##3}};
|
||||||
|
\end{tikzpicture}
|
||||||
|
}
|
||||||
|
\RedeclareSectionCommand[beforeskip=-55\vscale,afterskip=6\vscale]{chapter}
|
||||||
|
\setlength{\mtocshift}{-1\vscale}
|
||||||
|
}
|
||||||
|
|
||||||
|
% Lines
|
||||||
|
\renewcommand{\hrulefill}[1][0.4pt]{%
|
||||||
|
\leavevmode\leaders\hrule height #1\hfill\kern\z@%
|
||||||
|
}
|
||||||
|
|
||||||
|
\DeclareDocumentCommand{\chapterstylelines}{}{%
|
||||||
|
\renewcommand*{\chapterformat}{%
|
||||||
|
\chapappifchapterprefix{\nobreakspace}\scalebox{3.5}{\thechapter\autodot}%
|
||||||
|
}%
|
||||||
|
\renewcommand\chapterlinesformat[3]{%
|
||||||
|
%\vspace*{-1cm}%
|
||||||
|
\leavevmode%
|
||||||
|
\makebox[0pt][l]{%
|
||||||
|
\makebox[\textwidth][l]{\hrulefill[1pt]##2}%\hfill%\par%\bigskip
|
||||||
|
\makebox[\marginparsep][l]{}%
|
||||||
|
\makebox[\marginparwidth][l]{}%
|
||||||
|
}\\
|
||||||
|
%\vspace{.5cm}
|
||||||
|
\makebox[0pt][l]{%
|
||||||
|
\makebox[\textwidth][l]{##3}%
|
||||||
|
\makebox[\marginparsep][l]{}%
|
||||||
|
\makebox[\marginparwidth][l]{}%
|
||||||
|
}\\
|
||||||
|
\makebox[0pt][l]{%
|
||||||
|
\makebox[\textwidth+\marginparsep+\marginparwidth][l]{\hrulefill[1.1pt]}%
|
||||||
|
}%
|
||||||
|
\RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}
|
||||||
|
\setlength{\mtocshift}{-1\vscale}%
|
||||||
|
}
|
||||||
|
}
|
||||||
|
% The Kao style
|
||||||
|
\DeclareDocumentCommand{\chapterstylekao}{}{%
|
||||||
|
\IfWideLayout{%
|
||||||
|
\renewcommand*{\chapterformat}{%
|
||||||
|
\mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{2.85}{\thechapter\autodot}}%
|
||||||
|
}%
|
||||||
|
\renewcommand\chapterlinesformat[3]{%
|
||||||
|
\vspace{3.5\vscale}%
|
||||||
|
\if@twoside%
|
||||||
|
\Ifthispageodd{%
|
||||||
|
\smash{\makebox[0pt][l]{%
|
||||||
|
\parbox[b]{\textwidth - 6.2\hscale}{\flushright{##3}}%
|
||||||
|
\makebox[6.2\hscale][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
|
||||||
|
\parbox[b]{\marginparwidth}{##2}%
|
||||||
|
}}%
|
||||||
|
}{
|
||||||
|
\smash{\makebox[\textwidth + 6.2\hscale][r]{%
|
||||||
|
\parbox[b]{47.7\hscale + 6.2\hscale}{\flushright{##2}}%
|
||||||
|
\makebox[6.2\hscale][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
|
||||||
|
\parbox[b]{\textwidth}{\flushleft{##3}}%
|
||||||
|
}}%
|
||||||
|
}
|
||||||
|
\else%
|
||||||
|
\smash{\makebox[0pt][l]{%
|
||||||
|
\parbox[b]{\textwidth - 6.2\hscale}{\flushright{##3}}%
|
||||||
|
\makebox[6.2\hscale][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
|
||||||
|
\parbox[b]{\marginparwidth}{##2}%
|
||||||
|
}}%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
}{%
|
||||||
|
\renewcommand*{\chapterformat}{%
|
||||||
|
\mbox{\chapappifchapterprefix{\nobreakspace}\scalebox{2.85}{\thechapter\autodot}}%
|
||||||
|
}%
|
||||||
|
\renewcommand\chapterlinesformat[3]{%
|
||||||
|
\vspace{3.5\vscale}%
|
||||||
|
\if@twoside%
|
||||||
|
\Ifthispageodd{%
|
||||||
|
\smash{\makebox[0pt][l]{%
|
||||||
|
\parbox[b]{\textwidth}{\flushright{##3}}%
|
||||||
|
\makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
|
||||||
|
\parbox[b]{\marginparwidth}{##2}%
|
||||||
|
}}%
|
||||||
|
}{
|
||||||
|
\smash{\makebox[\textwidth][r]{%
|
||||||
|
\parbox[b]{\marginparwidth}{\flushright{##2}}%
|
||||||
|
\makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
|
||||||
|
\parbox[b]{\textwidth}{\flushleft{##3}}%
|
||||||
|
}}%
|
||||||
|
}
|
||||||
|
\else%
|
||||||
|
\smash{\makebox[0pt][l]{%
|
||||||
|
\parbox[b]{\textwidth}{\flushright{##3}}%
|
||||||
|
\makebox[\marginparsep][c]{\rule[-2\vscale]{1pt}{27.4\vscale+\f@size mm}}%
|
||||||
|
\parbox[b]{\marginparwidth}{##2}%
|
||||||
|
}}%
|
||||||
|
\fi%
|
||||||
|
}%
|
||||||
|
}%
|
||||||
|
\RedeclareSectionCommand[beforeskip=0cm,afterskip=10\vscale]{chapter}%
|
||||||
|
\setlength{\mtocshift}{-3.5\vscale}%
|
||||||
|
}
|
||||||
|
|
||||||
|
% Takes as input the image path and optionally the "beforeskip"
|
||||||
|
\DeclareDocumentCommand{\setchapterimage}{O{55\vscale} m}{%
|
||||||
|
\setchapterpreamble[o]{%
|
||||||
|
\vspace*{-27\vscale}\hspace*{\dimexpr - \hoffset - \oddsidemargin - 1in}%
|
||||||
|
\includegraphics[width=\paperwidth,height=#1+27\vscale,keepaspectratio=false]{#2}%
|
||||||
|
}%
|
||||||
|
\chapterstylebar%
|
||||||
|
% beforeskip=-(figure_height-top_margin)
|
||||||
|
\RedeclareSectionCommand[beforeskip=-#1, afterskip=6\vscale]{chapter}%
|
||||||
|
\setlength{\mtocshift}{0cm}%
|
||||||
|
}
|
||||||
|
|
||||||
|
% By default start with the kao style
|
||||||
|
\setchapterstyle{lines}
|
||||||
|
|||||||
Reference in New Issue
Block a user