Page LayoutCan't get chapter titles into page header (KOMA)

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
MisterArtC
Posts: 3
Joined: Fri Aug 07, 2020 10:52 pm

Can't get chapter titles into page header (KOMA)

Post by MisterArtC »

I am struggling to get the page headers I want in a scrbook document class (2-sided, 2 cols).

I want no header on the first (right/odd) chapter page, and the page number should be bottom-center.

Otherwise, the header should have a line underneath and a space (baselineskip) after that dividing the header and text block. Page number should be in the top-outer corner.

Centered in each header should be the book title on the left/even page and the current chapter on the right/odd page.

Text should be preferably roman, not italic, possibly bold

(For extra credit, why do the resulting PDF pages from my code have such a big bottom margin?)

Here is my MWE

Code: Select all

Code, edit and compile here:
\documentclass[headsepline,headings,letterpaper]{scrbook}
\usepackage{fontspec}
\usepackage[top=1.00in,bottom=1.00in,inner=1.25in,outer=.75in,headsep=12pt]{geometry}
\usepackage[fontsize=10pt,baseline=12pt]{grid}
\usepackage{scrlayer-scrpage}
\ifoot*{} %these 3 lines correctly put pg. numbers in header
\ofoot*{} %but 1st page should be bottom centered
\ohead*{\pagemark}
\cohead{chapter} % prints as literal string
\cehead{\textrm{title}} % but overwrite even pages with the title
\usepackage{multicol,lipsum}
\begin{document}
\chapter*{\centering Chapter Heading: March} % asterix removes chapter number
\begin{multicols}{2}
\lipsum[1-15]
\end{multicols}
\chapter*{\centering Chapter Heading: April}
\begin{multicols}{2}
\lipsum[16-30]
\end{multicols}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This code compiles (XeLaTeX) and the result is a mixed success. Page numbers are in the right place, except for the first page of the chapter. The centered text is treating what I thought were the variables — Title, chapter — as literals.

And like I noted above, as long as you're looking at my code, particularly the {geometry} options on line 3, I am totally stumped about why the bottom third of the pages is blank.

Thanks for your help. I spent a lot of time searching here and SX, not to mention struggling with the 565 (!) page KOMA-Script manual) and have succeeded only in getting more confused. But experts say that in this year of pandemic isolation, many of us are experiencing mental fog. That's my story, and I'm stickin' with it.

Thanks for your help,
MisterArtC

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Can't get chapter titles into page header (KOMA)

Post by Ijon Tichy »

First of all: Package grid does change the height of the text area. So the big bottom margin is a result of using this package, without setting a proper lines option. See the manual for more information.

Coming to the running head. KOMA-Script guide explains:
The starred variants of all sectioning commands produce unnumbered headings which do not appear in the table of contents or in the running head.
So \chapter* is not usable for automatic running heads.
And the guide also explains:
The absence of a running head often has an unwanted side effect. … KOMA-Script offers a
solution for this problem, described below.
And this "below" are the commands \addpart, \addchap and \addsec. So, if you want automatic running heads from your chapters, you have to use either \chapter (without star) or \addchap.

The page number is in the head, because you've placed it into the head: \ohead* means, outer part of the head of the headings and the plain page style. You've written, that you want it centered in the foot on chapter pages. So you have to use \ohead not \ohead* and add a \cfoot[\pagenumber]{} for the foot of the plain pages.

Some more note: you should not use \centering or other formatting commands inside the argument of, e.g., \addchap. The \centering would also move to the ToC and the running head. KOMA-Script provides user interfaces to change the formatting of several elements, e.g., \raggedchapter can be changed to change the alignment of chapters. The fonts of page header and footer can be changed by font element commands \setkomafont and \addtokomafont.

One minimal example for my suggestion would be:

Code: Select all

Code, edit and compile here:
\documentclass[headsepline,letterpaper,twocolumn]{scrbook}
\usepackage{fontspec}
\usepackage[top=1.00in,bottom=1.00in,inner=1.25in,outer=.75in,headsep=12pt]{geometry}
%\usepackage[fontsize=10pt,baseline=12pt]{grid}% Package grid changes the text height to (see option lines in the manual)
\usepackage{scrlayer-scrpage}
\automark[chapter]{chapter}
\clearpairofpagestyles % remove the default elements of headings and plain pages
\ohead{\pagemark} % page number right aligned in the head of headings pages only
\cfoot[\pagemark]{} % page number centered in foot of plain page
\cohead{\headmark} % prints the mark for odd pages, selected by \automark
\cehead{title} % non variable text on even pages
\setkomafont{pageheadfoot}{\normalcolor\bfseries}% use bold for page header and footer (see table 5.1 of the KOMA-Script manual for the default)
\usepackage{lipsum}
\let\raggedchapter\centering % center chapter headings
\begin{document}
\addchap{Chapter Heading: March} % \chapter* does not set a head mark!
\lipsum[1-15]
\addchap{Chapter Heading: April}
\lipsum[16-30]
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
BTW: None of the used class/packages has an option headings, so I've removed it.
Last edited by Ijon Tichy on Sun Mar 21, 2021 9:43 pm, edited 1 time in total.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
IbiloyeCA2021
Posts: 3
Joined: Sun Mar 21, 2021 9:18 pm

Can't get chapter titles into page header (KOMA)

Post by IbiloyeCA2021 »

Ijon Tichy wrote:First of all: Package grid does change the height of the text area. So the big bottom margin is a result of using this package, without setting a proper lines option. See the manual for more information.

Coming to the running head. KOMA-Script guide explains:
The starred variants of all sectioning commands produce unnumbered headings which do not appear in the table of contents or in the running head.
So \chapter* is not usable for automatic running heads.
And the guide also explains:
The absence of a running head often has an unwanted side effect. … KOMA-Script offers a
solution for this problem, described below.
And this "below" are the commands \addpart, \addchap and \addsec. So, if you want automatic running heads from your chapters, you have to use either \chapter (without star) or \addchap.

The page number is in the head, because you've placed it into the head: \ohead* means, outer part of the [o]head[/o] of the headings and the plain page style. You've written, that you want it centered in the foot on chapter pages. So you have to use \ohead not \ohead* and add a \cfoot[\pagenumber]{} for the foot of the plain pages.

Some more note: you should not use \centering or other formatting commands inside the argument of, e.g., \addchap. The \centering would also move to the ToC and the running head. KOMA-Script provides user interfaces to change the formatting of several elements, e.g., \raggedchapter can be changed to change the alignment of chapters. The fonts of page header and footer can be changed by font element commands \setkomafont and \addtokomafont.

Thanks so much, this hinted on similar puzzle I had.
MisterArtC
Posts: 3
Joined: Fri Aug 07, 2020 10:52 pm

Can't get chapter titles into page header (KOMA)

Post by MisterArtC »

Thanks for the helpful responses. However I am still not quite getting what I want.

First, I didn't know about the "lines" option in the Grid package because I've used Grid in some other projects and never had a problem. A better solution for me, instead of adding "lines=57" (or whatever) was to load the Geometry package with its options AFTER loading Grid. That way, the Geometry options overwrite, in effect, any conflicting Grid directions.

More perplexing to me is why I can't get the specified variable "title" to appear in the left/even headers. In line 7 I set title as "KOMA example" and it prints that way on the title page. If I change \automark options to be [title]{chapter}, it won't compile with an error msg I don't understand. ("Package scrlayer Error: numbering depth of `title' unknown." In this instance I can just enter the text of the title since it''ll be the same on all the even pages, but it really bothers me that I can't figure it out.

Thanks again!

Code: Select all

Code, edit and compile here:
\documentclass[headsepline,letterpaper,twocolumn]{scrbook}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[fontsize=10pt,baseline=12pt]{grid}
\usepackage[top=1.00in,bottom=1.00in,inner=1.25in,outer=.75in,headsep=12pt]{geometry} %setting top and bottom defines text block and effectively replaces any lines setting in Grid.
\usepackage{scrlayer-scrpage}
\automark[chapter]{chapter} % won't compile as ``\automark[title]{chapter} ``
\title{KOMA example}
\author{Random Writer, Ph.D.}
%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%
\maketitle
\tableofcontents
\clearpairofpagestyles % remove the default elements of headings and plain pages
\ohead{\pagemark} % page number right aligned in the head of headings pages only
\cfoot[\pagemark]{} % page number centered in foot of plain page
\cohead{\headmark} % prints the mark for odd pages, selected by \automark
\cehead{title} % non variable text on even pages
\setkomafont{pageheadfoot}{\normalcolor\bfseries}% use bold for page header and footer (see table 5.1 of the KOMA-Script manual for the default)
\let\raggedchapter\centering % center chapter headings
\addchap{Chapter Heading: March} % \chapter* does not set a head mark!
\lipsum[1-25]
\addchap{Chapter Heading: April}
\lipsum[16-30]
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Can't get chapter titles into page header (KOMA)

Post by Ijon Tichy »

MisterArtC wrote:More perplexing to me is why I can't get the specified variable "title" to appear in the left/even headers. In line 7 I set title as "KOMA example" and it prints that way on the title page. If I change \automark options to be [title]{chapter}, it won't compile with an error msg I don't understand.
\title is not a sectioning command. It is very, very different. It even does not print anything, but only fill an internal macro, that is used by \maketitle. So title is also not the name of a section level. But the arguments of \automark have to be such names:
scrguien wrote: \automark[<section level of the right mark>]{<section level of the left mark>}
[…]
The arguments should always be the name of a section level like part, chapter, section, subsection, subsubsection, paragraph, or subparagraph.
And because the document title is usually static for the whole document, IMHO it is not a kind of living/dynamic running head, but a static one. But the purpose of \automark is not to add a static but a dynamic running head automatically using the mark mechanism of TeX. There is no need to use the mark mechanism with static heads. The only thing you could do it to use the internal title macro as a static element:

Code: Select all

Code, edit and compile here:
\documentclass[headsepline,letterpaper,twocolumn]{scrbook}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[fontsize=10pt,baseline=12pt]{grid}
\usepackage[top=1.00in,bottom=1.00in,inner=1.25in,outer=.75in,headsep=12pt]{geometry} %setting top and bottom defines text block and effectively replaces any lines setting in Grid.
\usepackage{scrlayer-scrpage}
\automark[chapter]{} % automatically use chapter level for odd pages
\title{KOMA example}
\author{Random Writer, Ph.D.}
\clearpairofpagestyles % remove the default elements of headings and plain pages
\ohead{\pagemark} % page number right aligned in the head of headings pages only
\cfoot[\pagemark]{} % page number centered in foot of plain page
\cohead{\headmark} % prints the mark for odd pages, selected by \automark
\cehead{\csname @title\endcsname} % use the internal title contents for even pages
\setkomafont{pageheadfoot}{\normalcolor\bfseries}% use bold for page header and footer (see table 5.1 of the KOMA-Script manual for the default)
\let\raggedchapter\centering % center chapter headings
%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%
\maketitle
\tableofcontents
\addchap{Chapter Heading: March} % \chapter* does not set a head mark!
\lipsum[1-25]
\addchap{Chapter Heading: April}
\lipsum[16-30]
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
BTW: Someone could think, that something like:

Code: Select all

Code, edit and compile here:
\documentclass[headsepline,letterpaper,twocolumn]{scrbook}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage[fontsize=10pt,baseline=12pt]{grid}
\usepackage[top=1.00in,bottom=1.00in,inner=1.25in,outer=.75in,headsep=12pt]{geometry} %setting top and bottom defines text block and effectively replaces any lines setting in Grid.
\usepackage{scrlayer-scrpage}
\automark[chapter]{} % won't compile as ``\automark[title]{chapter} ``
\title{KOMA example}
\markleft{\csname @title\endcsname}
\author{Random Writer, Ph.D.}
\clearpairofpagestyles % remove the default elements of headings and plain pages
\ohead{\pagemark} % page number right aligned in the head of headings pages only
\cfoot[\pagemark]{} % page number centered in foot of plain page
\chead{\headmark} % prints the mark for odd pages, selected by \automark
\setkomafont{pageheadfoot}{\normalcolor\bfseries}% use bold for page header and footer (see table 5.1 of the KOMA-Script manual for the default)
\let\raggedchapter\centering % center chapter headings
%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%
\maketitle
\tableofcontents
\addchap{Chapter Heading: March} % \chapter* does not set a head mark!
\lipsum[1-25]
\addchap{Chapter Heading: April}
\lipsum[16-30]
\end{document}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
would also work. But it does not, because \tableofcontents, \listoffigures etc. always set both marks, if automatic running heads are used. This is one more reason why it would not help, if \automark would be able to use title as an argument: Other automatic titles are very easily be able to overwrite it and this depends hardly on the used class not on package scrlayer-scrpage.

BTW: General settings should be done before \begin{document}.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
MisterArtC
Posts: 3
Joined: Fri Aug 07, 2020 10:52 pm

Can't get chapter titles into page header (KOMA)

Post by MisterArtC »

Ijon Tichy, you should write the manual! Your explanations is much clearer. Thank you again!

MisterArtC
Post Reply