1

This is a follow up to controlling the gap between footer and body of text. Remember, the goal is to max text within a page. To that end, how can I use the drop or wrap shapes to work using titlesec (no examples]2). How to set parameters—I guess using \titleformat—of titlesec such that the first header looks as follows?

"Gibberish[as long a skip as possible]Ch. 1"?

Finally, how can I reduce the gap between chapter's header and the top of the page?

\documentclass[a6paper, DIV=20]{scrreprt}
%\documentclass{scrreprt}
\usepackage{fontawesome}
\usepackage[T1]{fontenc}
\usepackage{lastpage}
\usepackage{lipsum} % Dummy Text
\usepackage{titlesec}
\usepackage{titleps}
\usepackage{xparse}
\usepackage{tabularx}
\usepackage{hyperref}  

\setlength{\footskip}{24pt}
\renewcommand*\familydefault{\sfdefault}

\NewDocumentCommand{\chapterLabel}{}{Ch. \thechapter}
\NewDocumentCommand{\chapterMark}{}{U HAVE TO DEFINE IT!}
\NewDocumentCommand{\setchapterMark}{m}
{%
  \RenewDocumentCommand{\chapterMark}{}{#1}
}

\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\NewDocumentCommand{\myheader}
{mm}
{%
  \begin{tabularx}{\textwidth}{@{}XR@{}}#1&#2\end{tabularx}
}  

%\newpagestyle{〈name〉}
%[〈global-style〉]
%{〈commands〉}

%setfoot[〈even-left〉][〈even-center〉][〈even-right〉]
%{〈odd-left〉}{〈odd-center〉}{〈odd-right〉}

\newpagestyle{main}
{
  \setfoot{\thepage/\pageref{LastPage}}
  {}
  {\chapterLabel}
}  

\newpagestyle{special}
{
  \setfoot{\thepage/\pageref{LastPage}}
  {}
  {\chapterMark}
}  

%\titleformat{〈command〉}[〈shape〉]{〈format〉}{〈label〉}{〈sep〉}{〈before-code〉}[〈after-code〉]

%\pagenumbering{gobble}
\pagestyle{main}
\assignpagestyle{\chapter}{empty}
% \titleformat{\chapter} % command
% [drop]%hang|block|display|runin|leftmargin|rightmargin|drop|wrap|frame
% {}% format
% {\chapterLabel}% label
% {}% sep
% {}% before code
%  [〈after-code〉]

\begin{document}
\title{Lorem Ipsum}
\author{Dolor S. Amet}
\maketitle

\chapter{Gibberish}

\lipsum[1-2]

\clearpage
\pagestyle{empty}
\setchapterMark{\faBook}
\pagestyle{special}
%\chapter*{\chapterMark~Bibliography}
\chapter*{\myheader{Bibliography}{\chapterMark}}
Let's make that ....

\newpage

... span a second page

\end{document}

Shot 1

Shot 2

Shot 3

Erwann
  • 2,100
  • 1
    To reduce the gap between ths chapter heading and the top of page, you have the \titlespacing* command. However, there might be conflicts using titlesec with a koma-script document class. – Bernard Oct 03 '19 at 08:17
  • You should be aware of the fact that titlesec and KoMa classes don't go along. – egreg Oct 04 '19 at 11:57

3 Answers3

1

Do not use packages titlesec and titleps with KOMA-Script classes. They are not compatible (even if the example works with the current versions). So here is a suggestion without these packages:

\documentclass[a6paper, DIV=20]{scrreprt}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
%\providecommand*\Ifnumbered{\ifnumbered}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{fontawesome}
\usepackage[T1]{fontenc}
\usepackage{lastpage}
\usepackage{lipsum} % Dummy Text
\usepackage[manualmark]{scrlayer-scrpage}
\usepackage{xparse}
\usepackage{tabularx}
\usepackage{hyperref}

\setlength{\footskip}{24pt}
\renewcommand*\familydefault{\sfdefault}

\NewDocumentCommand{\chapterSymbol}{}{}
\NewDocumentCommand{\setchapterSymbol}{m}
{%
  \RenewDocumentCommand\chapterSymbol{}{#1}%
}

\addtokomafont{pageheadfoot}{\normalfont}
\clearpairofpagestyles
\ifoot*{\thepage/\pageref{LastPage}}
\ofoot*{\rightmark}
\renewcommand*\chaptermark[1]{\markright{\Ifnumbered{chapter}{Ch. \thechapter}{\chapterSymbol}}}
\renewcommand*\chapterpagestyle{empty}

\NewDocumentCommand{\myheader}
  {mm}
  {%
    \renewcommand\tabularxcolumn[1]{b{##1}}%
    \begin{tabularx}{\textwidth}[b]{@{}Xr@{}}%
      \parbox[b]{\linewidth}{\raggedright#1}&#2%
    \end{tabularx}%
  }

\renewcommand*\chapterformat{Ch. \thechapter}
\newcommand*\originalchapterlinesformat{}
\let\originalchapterlinesformat\chapterlinesformat
\renewcommand\chapterlinesformat[3]{%
  \Ifstr{#1}{chapter}
  {%
    \Ifstr{#2}{}
      {\myheader{#3}{\chapterSymbol}}
      {\myheader{#3}{#2}}%
    \setchapterSymbol{}%
  }
  {\originalchapterlinesformat{#1}{#2}{#3}}%
}

\RedeclareSectionCommand[
  beforeskip=0pt,afterindent=false,% if you use an older KOMA-Script version replace the line by beforeskip=-1sp
  afterskip=.5\baselineskip plus .05\baselineskip minus .1\baselineskip
]{chapter}

\begin{document}
\title{Lorem Ipsum}
\author{Dolor S. Amet}
\maketitle
\tableofcontents

\chapter{Gibberish}
\lipsum[1-2]

\setchapterSymbol{\faBook}
\addchap{Bibliography}
Let's make that ....
\newpage
... span a second page
\end{document}

Result:

enter image description here

It is also possible to have a chapter title that does not fit in one line:

\chapter{Gibberish and some more text}
\lipsum[3-4]

enter image description here

esdd
  • 85,675
  • Thank you, I'll fall back on that if I can't find another way, but like the idea of modularity (one package, one purpose), hence toying with titlesec. What I'm stuck on right now is getting an A6 layout with non Koma-Script classes. – Erwann Oct 03 '19 at 13:42
  • Then you should really use a standard class. But note, the usage of many different packages also enlarges the chance of incompatibilities. – esdd Oct 03 '19 at 13:47
  • "enlarges the chance of incompatibilities": not if they are modular. – Erwann Oct 03 '19 at 13:51
0

Because this post was about titlesec and I am told it would conflict with Koma-script, I'm using a standard class. Putting everything together, here's the closest I get to the spec. <> and () are just to see how titleformat works.

\documentclass{report}
\usepackage{fontawesome}
\usepackage{expl3}
\usepackage[
paper=a6paper,
layout=a6paper,
centering,
,left=1em
,right=1em
,top=1em
,bottom=4em
]{geometry}
\usepackage{lastpage}
\usepackage[explicit]{titlesec}
%\usepackage[DIV=20]{typearea}% throws off the font
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{xparse}

%\setlength{\footskip}{24pt}
\renewcommand*\familydefault{\sfdefault}

\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\NewDocumentCommand{\myheader}
{mm}
{%
  \begin{tabularx}{\textwidth}{@{}XR@{}}#1&#2\end{tabularx}
}  

%titlesec
\titleformat{name=\chapter}
[frame]
{\normalfont\bfseries}
{%
  \filinner
  % \truncchar{left}{2}{\chaptertitlename}. \% An idea...
  \chapterLabel
}
{0.5em}
{\large\filouter \textless #1\textgreater}
\titleformat{name=\chapter,numberless}
[frame]
{\normalfont\bfseries}
{%
  \filinner
    \chapterMark
}
{0.5em}
{\large\filouter (#1)}
\titlespacing{\chapter}{0pt}{*0}{*0}
\NewDocumentCommand{\chapterLabel}{}{Ch. \thechapter}
\NewDocumentCommand{\chapterMark}{}{DEFINE IT!}
\NewDocumentCommand{\setchapterMark}{m}
{%
  \RenewDocumentCommand{\chapterMark}{}{#1}
}
% titleps
\newpagestyle{main}
{
  \setfoot{\thepage/\pageref{LastPage}}
  {}
  {\chapterLabel}
}  
\newpagestyle{special}
{
  \setfoot{\thepage/\pageref{LastPage}}
  {}
  {\chapterMark}
}  
\pagestyle{main}
\assignpagestyle{\chapter}{empty}

\begin{document}

\chapter[Intro]{Introduction}

\lipsum

\newpage% \clearpage
\setchapterMark{\faBook}
\pagestyle{special}
\chapter*{Bibliography}
%\chapter*{\myheader{Bibliography}{\chapterMark}}
Let's make that ....

\newpage

... span a second page

%runin
%leftmargin
%rightmargin
%wrap
%frame

\end{document}

Shot 1 Shot 2 Shot 3 Shot 4

Erwann
  • 2,100
0

Here is a solution with the standard report class and, of course titlesec (I had to replace fontawesome, which isn't installed on my system, with fontawesome5):

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a6paper, margin=20pt, bottom=34pt, footskip=24pt, showframe]{geometry}
\usepackage{fontawesome5}
\usepackage{lastpage}
\usepackage{lipsum} % Dummy Text
\usepackage[pagestyles]{titlesec}
\usepackage{xparse}
\usepackage{tabularx}
\usepackage{hyperref}

\renewcommand*\familydefault{\sfdefault}

\NewDocumentCommand{\chapterLabel}{}{Ch. \thechapter}
\NewDocumentCommand{\chapterMark}{}{U HAVE TO DEFINE IT!}
\NewDocumentCommand{\setchapterMark}{m}
{%
  \RenewDocumentCommand{\chapterMark}{}{#1}
}%

\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\newpagestyle{main}{%
  \setfoot{\thepage/\pageref{LastPage}}{}{\chapterLabel}
}%

\newpagestyle{special}{%
  \setfoot{\thepage/\pageref{LastPage}}{}{\chapterMark}
}%

\titleformat{\chapter}{\thispagestyle{empty}\sffamily\Huge}{\rlap{\makebox[\textwidth][r]{Ch. \thechapter}}}{0em}{}
\titlespacing*{\chapter}{0pt}{-5ex}{4ex}

\pagestyle{main}

\begin{document}

\title{Lorem Ipsum}
\author{Dolor S. Amet}
\maketitle
%
\chapter{Gibberish}
%
\lipsum[1-5]

\chapter{More Gibberish}
\lipsum[6-12]
\clearpage

\setchapterMark{\faBook}
\pagestyle{special}
\chapter*{Bibliography}
Let's make that
\newpage
... span a second page

\end{document} 

enter image description here

Bernard
  • 271,350
  • Could you explain rlap and how you would modify it for font size, say, \large? – Erwann Oct 03 '19 at 21:13
  • \rlap is a TeX primitivewhich places a box at the right of the insertion point, but doesn't move the latter after the box, as though this box had no width. There exists a symmetric \llap command. To modify the font size, you just replace \Huge with \large in the second argument of \titleformat. – Bernard Oct 03 '19 at 21:40
  • I know how to modify the font size, but it throws off the rest. – Erwann Oct 03 '19 at 22:36
  • What do you mean? – Bernard Oct 03 '19 at 22:38
  • Have a look here: https://imgur.com/meHCdTL. Also, why is rlap is needed here? It seems as though it's a bit of a hack. – Erwann Oct 03 '19 at 22:42
  • I see. You have to adjust \titlespacing* for another font size. For \large, you can use \titlespacing*{0pt}{-3ex}{4ex}. The 2nd argument is the vertical spacing above the heading, the last argument is the vertical spacing below. \rlap is used to not have the chapter title after the chapter label. – Bernard Oct 03 '19 at 22:51