4

I’m struggling to replicate a corporate design in (Lua)LaTeX. The problems arise with a very special treatment of the page head (and margins):

The header is very large with a page number in the top outer corner and a line at the bottom. Only on pages with a chapter title the chapter title should be set in that empty space. I’ve solved this with TikZ (following http://texblog.net/latex-archive/uncategorized/fancy-chapter-tikz/). However, I can’t get rid of the empty space at the beginning of the text block after a chapter heading.

Space to be removed

I’ve tried \titlespacing{\chapter}{0pt}{0pt}{0pt}, \RedeclareSectionCommand[afterskip=0pt,beforeskip=0pt]{chapter} and \renewcommand{\chapterheadendvskip}{0pt} but none of them do what I expect.

MWE:

\documentclass[%
  openany
  ,a4paper
  ,footsepline=0.5pt
  ,headings=small
  ]{scrbook}
\usepackage{scrlayer-scrpage}

\usepackage[%
  a4paper
  ,inner=26mm
  ,outer=7mm
  ,top=81.5mm
  ,bottom=31.5mm
  ,headheight=32pt
  ,headsep=54mm
  ,showframe
  ]{geometry}

\usepackage{lipsum}
\usepackage{multicol}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{tikzpagenodes}
\usepackage[explicit]{titlesec}

\titlespacing{\chapter}{0pt}{0pt}{0pt}
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \fontsize{32pt}{30.5pt}}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}{%
    \begin{tikzpicture}[remember picture,overlay, every node/.style={inner sep=0,outer sep=0, anchor=base, baseline}]
      \coordinate (chapter) at ($(current page text area.north west)+    (0,7mm)$);
      \node[above right, text width=\textwidth] at (chapter) {\chapterlabel #1};
\end{tikzpicture}
  }

%\RedeclareSectionCommand[afterskip=0pt,beforeskip=0pt]{chapter}
%\renewcommand{\chapterheadendvskip}{0pt}

\clearscrheadfoot
\ohead{\pagemark} 
\chead{%
  \begin{tikzpicture}[remember picture,overlay, every node/.style={inner sep=0,outer sep=0}]
    \coordinate (hsepline) at ($(current page text area.north west)+(0,+3.5mm)$);
    \draw [line width = 3pt] (hsepline) -- +(\textwidth,0);
  \end{tikzpicture}
}
\renewcommand{\chapterpagestyle}{scrheadings}

\title{Title}
\author{Me}
\date{2015}
\begin{document}
\maketitle
\begin{multicols}{2}[\chapter{A very very very very long chapter title spanning two lines}]
\lipsum[4]
\end{multicols}
\begin{multicols}{2}[\chapter{Chapter}]
\lipsum
\end{multicols}
\clearpage
\thispagestyle{empty}
Back matter
\end{document}

Edit: With \titlespacing{\chapter}{0pt}{-10mm}{0pt}, single-line chapter heads behave as desired but chapters whose titles span two lines still show the gap. However, with \titlespacing{\chapter}{0pt}{-10mm}{-10mm} the gap disappears from long titles whereas the text of single line chapter headings gets shifted too far upwards: Too little space

5
  • Have you tried just after your chapter \vspace{-1cm}. Not very elegant solution, but i does the job for me. Commented Jun 3, 2015 at 11:55
  • @Arne which position do you mean? pos1 or pos2 in \begin{multicols}{2}[\chapter{Chapter}pos1]pos2 ?
    – georgd
    Commented Jun 3, 2015 at 12:05
  • 1
    I've copied the code, and tried the solution I presented. In fact my problem was not exact the same, I wanted to decrease the space between, and that worked fine for section, subsection... but no here. Maybe this: tex.stackexchange.com/questions/111643/… will help you? Commented Jun 3, 2015 at 12:20
  • 1
    Thank you! The question you linked to contains the answer in Gonzalo’s comment to his answer. It is the second argument to \titlespacing{\chapter} (“before-sep”) that has to be changed. I was always manipulating the third one (“after-sep”)
    – georgd
    Commented Jun 3, 2015 at 12:31
  • Ok, I was too quick. It does not help if the chapter title spans over two lines. In this case, the empty space stays.
    – georgd
    Commented Jun 3, 2015 at 12:37

1 Answer 1

3

scrlayer-scrpage

Note that the usage of titlesec together with a KOMA-Script class is not recommended. Here is a suggestion using a defining a new page style that inserts the chapter titles

enter image description here

\documentclass[%
   openany
  ,a4paper
  ,headings=small
  ]{scrbook}
\usepackage[%
  a4paper
  ,inner=26mm
  ,outer=7mm
  ,top=81.5mm
  ,bottom=31.5mm
  ,headheight=32pt
  ,headsep=54mm
  ,showframe
  ]{geometry}
\usepackage{lipsum}
\usepackage{multicol}

\usepackage[footsepline=.5pt,manualmark]{scrlayer-scrpage}
\clearpairofpagestyles
\ohead*{\pagemark}

\ModifyLayer[foreground]{scrheadings.head.odd}
\ModifyLayer[foreground]{scrheadings.head.even}
\ModifyLayer[foreground]{plain.scrheadings.head.odd}
\ModifyLayer[foreground]{plain.scrheadings.head.even}

\DeclareNewLayer[
  foreground
  ,headsep
  ,addvoffset=-3mm
  ,contents={\vfill\rule[-\dp\strutbox]{\layerwidth}{3pt}}
]{hc.headsep.bottom.line}
\DeclareNewLayer[
  clone=hc.headsep.bottom.line,
  ,addvoffset=-4mm
  ,contents={\vfill{\usekomafont{chapter}\leftmark}}
]{hc.headsep}
\AddLayersToPageStyle{scrheadings}{hc.headsep.bottom.line}

\DeclareNewPageStyleByLayers{chapterpage}{}
\ForEachLayerOfPageStyle{scrheadings}{\AddLayersToPageStyle{chapterpage}{#1}}
\AddLayersToPageStyle{chapterpage}{hc.headsep}

\setkomafont{chapter}{\normalfont\fontsize{32pt}{30.5pt}\selectfont}

\makeatletter
\newcommand*\headchapter{\@ifstar{\@sheadchapter}{\@headchapter}}
\newcommand*\@headchapter[1]{%
  \clearpage\thispagestyle{chapterpage}\refstepcounter{chapter}%
  \markleft{\thechapter\enskip#1}%
  \addchaptertocentry{\thechapter}{#1}%
}
\newcommand*\@sheadchapter[1]{%
  \clearpage\thispagestyle{chapterpage}%
  \markleft{#1}%
}
\newcommand\addheadchap[1]{%
  \clearpage\thispagestyle{chapterpage}%
  \markleft{#1}%
  \addchaptertocentry{}{#1}%
}
\makeatother
\deftocheading{toc}{\headchapter*{\contentsname}}

\title{Title}
\author{Me}
\date{2015}
\begin{document}
\maketitle
\tableofcontents
\begin{multicols}{2}[\headchapter{Chapter One}]
\lipsum[4]
\end{multicols}
\begin{multicols}{2}[\headchapter{A very very very very long chapter title spanning two lines}]
\lipsum[4]
\end{multicols}
\headchapter{Chapter Three}
\begin{multicols}{2}
\lipsum\lipsum
\end{multicols}
%
\addheadchap{Test}
\lipsum
\clearpage
\thispagestyle{empty}
Back matter
\end{document}

scrlayer

Here is an additional suggestion using only scrlayer instead scrlayer-scrpage.

Code:

\documentclass[%
   openany
  ,a4paper
  ,headings=small
  ]{scrbook}
\usepackage[%
  a4paper
  ,inner=26mm
  ,outer=7mm
  ,top=81.5mm
  ,bottom=31.5mm
  ,headheight=32pt
  ,headsep=54mm
  ,showframe
  ]{geometry}
\usepackage{lipsum}
\usepackage{multicol}

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  oddpage,
  area={26mm}{\dimexpr81.5mm-32pt-54mm\relax}{\textwidth}{32pt},
  contents={\vfill\hfill\pagemark}
]{hc.head.odd}
\DeclareNewLayer[
  clone=hc.head.odd,
  evenpage,
  hoffset=7mm,
  contents={\vfill\pagemark}
]{hc.head.even}
\DeclareNewLayer[
  foreground
  ,headsep
  ,addvoffset=-3mm
  ,contents={\vfill\rule[-\dp\strutbox]{\layerwidth}{3pt}}
]{hc.headsep.bottom.line}
\DeclareNewLayer[
  foreground,
  ,footskip,
  ,contents={\vfill\rule[-\dp\strutbox]{\layerwidth}{.5pt}}
]{hc.footskip.bottom.line}
\DeclareNewLayer[
  clone=hc.headsep.bottom.line,
  ,addvoffset=-4mm
  ,contents={\vfill{\usekomafont{chapter}\leftmark}}
]{hc.headsep}

\DeclareNewPageStyleByLayers{plain.hc}{%
  hc.head.odd,hc.head.even,%
  hc.headsep.bottom.line,%
  hc.footskip.bottom.line%
}
\DeclareNewPageStyleByLayers{chapterpage.hc}{%
  hc.head.odd,hc.head.even,%
  hc.headsep,%
  hc.headsep.bottom.line,%
  hc.footskip.bottom.line%
}
\DeclarePageStyleAlias{plain}{plain.hc}
\DeclarePageStyleAlias{chapterpage}{chapterpage.hc}
\pagestyle{plain}

\setkomafont{chapter}{\normalfont\fontsize{32pt}{30.5pt}\selectfont}

\makeatletter
\newcommand*\headchapter{\@ifstar{\@sheadchapter}{\@headchapter}}
\newcommand*\@headchapter[1]{%
  \clearpage\thispagestyle{chapterpage}\refstepcounter{chapter}%
  \markleft{\thechapter\enskip#1}%
  \addchaptertocentry{\thechapter}{#1}%
}
\newcommand*\@sheadchapter[1]{%
  \clearpage\thispagestyle{chapterpage}%
  \markleft{#1}%
}
\newcommand\addheadchap[1]{%
  \clearpage\thispagestyle{chapterpage}%
  \markleft{#1}%
  \addchaptertocentry{}{#1}%
}
\makeatother
\deftocheading{toc}{\headchapter*{\contentsname}}

\title{Title}
\author{Me}
\date{2015}
\begin{document}
\maketitle
\tableofcontents
\begin{multicols}{2}[\headchapter{Chapter One}]
\lipsum[4]
\end{multicols}
\begin{multicols}{2}[\headchapter{A very very very very long chapter title spanning two lines}]
\lipsum[4]
\end{multicols}
\headchapter{Chapter Three}
\begin{multicols}{2}
\lipsum\lipsum
\end{multicols}
%
\addheadchap{Test}
\lipsum
\clearpage
\thispagestyle{empty}
Back matter
\end{document}

The result is the same as above.

3
  • Thank you! Your solution is really great! I think, I’ll have to learn more about scrlayer, it seems to be a very useful package.
    – georgd
    Commented Jun 5, 2015 at 7:29
  • Just one thing I don’t understand. Why is the parbox in hc.headsep aligned with [c]?
    – georgd
    Commented Jun 5, 2015 at 7:38
  • 1
    [b] could also be used. But I have updated my answer. Now the \parbox commands are replaced by the usage of \vfill
    – esdd
    Commented Jun 5, 2015 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .