Page LayoutPage numbers are not right-aligned, header line not shown

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
dmarc
Posts: 7
Joined: Sat Aug 20, 2022 3:37 pm

Page numbers are not right-aligned, header line not shown

Post by dmarc »

Hey,

I'm new to latex and I'd like to write my bachelors thesis but I'm facing some problems, shown in the minimal working example below. Could you please help me with the following struggles?
  1. page numbers at the first page of each chapter are centered but should be on the right.
  2. The description of the chapter in the headers only works if the chapter contains a section. What do I have to do if I want the chapter number and name to appear in the header if there is no section or the section number and name to appear if there is a section (as it currently already works very well)?
  3. How can I make the space between two chapters smaller in the table of contents? When I add chapters manually to the table of contents it already works very well. However, the same procedure does not work for chapters that I add with \chapter.

Code: Select all


\documentclass[a4paper,12pt]{scrreprt}
\usepackage[left= 2.5cm,right = 2.5cm, bottom = 2.5cm, top = 2.5cm]{geometry}
\usepackage{fancyhdr}
\usepackage[english]{babel}
\usepackage{blindtext}

\pagestyle{fancy}
%
\lhead{}
\chead{}
\rhead{\slshape \rightmark}
%%
\lfoot{}
\cfoot{}
\rfoot{\thepage}
%%
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}
\pagestyle{empty}

Title page
\newpage


\pagestyle{fancy}
\pagenumbering{roman}
\setcounter{page}{2}


\addtocontents{toc}{\protect\vspace{-5pt}}
\addcontentsline{toc}{chapter}{list of figures}
\listoffigures
\addtocontents{toc}{\protect\vspace{-5pt}}
\newpage
\addtocontents{toc}{\protect\vspace{-5pt}}
\addcontentsline{toc}{chapter}{list of tables}
\listoftables
\newpage

\tableofcontents
\newpage



\pagenumbering{arabic}
\chapter{test chapter}
\blindtext[10]

\chapter{test chapter two}
\section{test section one}
\blindtext[10]


\end{document}


Thank you so much for your help!

Marc

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Page numbers are not right-aligned, header line not shown

Post by Bartman »

If you insert the title page with commands or an environment of the same name provided for this purpose, you don't have to change the page style or force a page break.

Please note the warning about the fancyhdr package in your log file.

You should find the answer to the first question in section 5.4. Using Predefined Page Styles of the KOMA-Script manual. Pay your attention to the starred version of the commands listed there.

The autooneside option in the next section should help answer the second question.
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

Page numbers are not right-aligned, header line not shown

Post by MjK »

Maybe it's

Code: Select all

\documentclass[a4paper,12pt,
  english,% See below.
  headsepline,% Add a separation line below the head.
  twoside=false,% Single sided document
  listof=totoc,% Seems you want toc entries for list of figures and list of
               % tables. → KOMA-Script manual for more information (either
               % scrguide-de.pdf or scrguien-en.pdf).
]{scrbook}% Class changed, because it seems you want a roman numbered front matter
\usepackage[left= 2.5cm,right = 2.5cm, bottom = 2.5cm, top = 2.5cm]{geometry}% Note recommended settings, but seems you want such ugly settings for the margins and typing area.  :shock: 
\usepackage{babel}% Option moved to be uses by all packages, that support it.
\usepackage{blindtext}

\usepackage[automark]{scrlayer-scrpage}% → KOMA-Script manual (either
                                   % scrguide-de.pdf or scrguide-en.pdf)
\clearpairofpagestyles% All these commands are explained in the
\ohead{\headmark}% KOMA-Script manual.
\ofoot*{\pagemark}% Note the * and also read about \pagemark.

\DeclareTOCStyleEntry[beforeskip=0pt]{chapter}{chapter}% Not extra vertical
                                % space before chapter style entries to ToC
                                % of chapters. → KOMA-Script manual

\begin{document}
\frontmatter% → KOMA-Script manual
\begin{titlepage}% → KOMA-Script manual
Title page
\end{titlepage}

\listoffigures
\listoftables
\tableofcontents

\mainmatter

\chapter{test chapter}
\blindtext[10]

\chapter{test chapter two}
\section{test section one}
\blindtext[10]

\end{document}
you are searching for. Maybe you also want the option @Bartman has told you to read in the KOMA-Script manual. You should also read the documentation of the package, the options and the commands I've used. You can find all of them in the KOMA-Script manual (the link shows the old English one, but there are new versions in German and English available on CTAN or on your computer, if your TeX distribution is up-to-date). There are also several examples for page head and foot with and without scrlayer-scrpage in the KOMA-Script wiki. This is also available in German.

There is also information about making a title page in the Wiki.
My main topics are KOMA-Script and other questions related to my packages. If I reply to any other topic or if you've not yet added a minimal working example, please do not expect any further response. And please don't forget to tag examples as code.
dmarc
Posts: 7
Joined: Sat Aug 20, 2022 3:37 pm

Page numbers are not right-aligned, header line not shown

Post by dmarc »

Thank you so much @MjK and @Bartman!
I've adjusted some content to your script, MjK. I've noticed, that \ofoot* puts the pagenumber on the chapter entry pages to the rigth boarder, so far this works well.

But unfortunately there are still some issues with the following:
  1. when a chapter contains a section, I'd like the number and the name of the section to appear in the heading, not the chapters one. (Just like the result you receive, when trying the example from the English KOMA guide page 270 but right-aligned.):

    Code: Select all

    \documentclass{scrreprt}
    \usepackage[autooneside=false]{scrlayer-scrpage}
    \automark[section]{chapter}
    \usepackage{lipsum}
    \begin{document}
    \chapter{chapter}
    \lipsum[1-20]
    \section{section}
    \lipsum[21-40]
    \end{document}
    
  2. Changing the class results in, for example, the chapters of the appendix are no longer being preceded by "A." as is the case with the "scrreport" class. I would like to have the result of "scrreport" here.
  3. The spacing in the table of contents basically works very well, but do you happen to know if it is possible that the spacing is kept small only for the directories, but normal for the normal chapters?
  4. I'd like to label a minisection. As far as I know it's not possible. Thefore I've chosen \subsubsection, since it's also not numbered. To adjust the vertical spacing after the subsubsection, I've added the following code to make it equal to die spacing of minisec/paragraph, but the spacing is still larger. I'm using \onehalfspacing at 12pt.
    \RedeclareSectionCommand[%
    %beforeskip=-2\baselineskip,
    afterskip=0.167\baselineskip
    ]{subsubsection}

Code: Select all

\documentclass[a4paper,12pt,
  english,% See below.
  headsepline,% Add a separation line below the head.
  twoside=false,% Single sided document
  listof=totoc,% Seems you want toc entries for list of figures and list of
               % tables. → KOMA-Script manual for more information (either
               % scrguide-de.pdf or scrguien-en.pdf).
]{scrbook}% Class changed, because it seems you want a roman numbered front matter
\usepackage[left= 2.5cm,right = 2.5cm, bottom = 2.5cm, top = 2.5cm]{geometry}
\usepackage{babel}% Option moved to be uses by all packages, that support it.
\usepackage{blindtext}


\usepackage[automark]{scrlayer-scrpage}% → KOMA-Script manual (either
                                   % scrguide-de.pdf or scrguide-en.pdf)
\clearpairofpagestyles% All these commands are explained in the
\ohead{\headmark}% KOMA-Script manual.
\automark[section]{chapter}
\ofoot*{\pagemark}% Note the * and also read about \pagemark.

\DeclareTOCStyleEntry[beforeskip=0pt]{chapter}{chapter}% Not extra vertical
                                % space before chapter style entries to ToC
                                % of chapters. → KOMA-Script manual

\begin{document}
\frontmatter% → KOMA-Script manual
\begin{titlepage}% → KOMA-Script manual
Title page
\end{titlepage}

\listoffigures
\listoftables
\tableofcontents

\newcounter{backmatterpage}
\setcounter{backmatterpage}{\value{page}}
\stepcounter{backmatterpage}

\mainmatter

\chapter{test chapter}
\blindtext[10]

\chapter{test chapter two}
\section{test section one}
\blindtext[10]

\backmatter
\appendix

\pagenumbering{roman}
\setcounter{page}{\value{backmatterpage}}
\chapter{Appendix}
\blindtext[10]


\end{document}
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

Page numbers are not right-aligned, header line not shown

Post by MjK »

If autooneside=false has the result you expect, use it. Why not? This is the reason it does exist. However, maybe \automark*{section} (note the star and read the documentation in the manual) would be the thing you really want. But I'm not sure. Only you can decide this.

But I'm sure, you don't want to use \backmatter. See the manual for more information, what the command does, i.e., what the implications of this command on chapter numbering are.

What do you expect from labels to not numbered section? A \ref will never show a correct number. So only \pageref would make sense and this is possible for \minisec and even to any text position inside a section without special element.

Switching back to roman numbering at the end of the document does not make any sense. Before computer typesetting engines roman numbers have been used, because the ToC and similar lists have been made after typesetting the main matter. And because mostly it was unclear, how many pages ToC, LoF, LoT, Preface etc. would have, all page references in the main matter would need to be changed after generation of these lists. So the typesetting would have to start again. To much work. For the same reason page references to later pages have been unwanted. Only references to chapter or section numbers have been allowed in most cases. But with computers several passes for the typesetting are no longer an issue. So roman page numbers in the front matter are also not needed any longer. But because they are traditionally in some languages they are still common. But roman numbers in the backmatter never made sense and so do not make any sense. Continuing the roman page numbers from the frontmatter are even evil. The main sense of page numbers are page references either within a document or into a document. But with roman page numbers at the beginning continued at the end, nobody know if page vii is the 7th page of the document or somewhere at the end. This is self-defeating. I recommend to never do such nonsense. An I will never support it.

Also: If chapter entries in the ToC are set with a vertical distance before, you should do so for all chapter entries. It is a fundamental rule of typography to do the same thing in the same document always the same. However, if you want to change setting inside the ToC you have to write the changes into the *.toc file. But once again: I do not actively support such nonsense. It hurts me to much. I'm going crazy, if I only think about it.
My main topics are KOMA-Script and other questions related to my packages. If I reply to any other topic or if you've not yet added a minimal working example, please do not expect any further response. And please don't forget to tag examples as code.
dmarc
Posts: 7
Joined: Sat Aug 20, 2022 3:37 pm

Page numbers are not right-aligned, header line not shown

Post by dmarc »

\automark*{section} is exactly what I've been looking for!

You're right, I decided not to use \backmatter, I just read it in connection with scrbook.

I'm gonna use \pageref it just works perfect. I wanted to use the label at first to be able to jump directly to the point in the PDF. But actually it's nonesense.

Also thank you so much for the background information about typesetting, I adjust my pagenumbers.
User avatar
MjK
Posts: 89
Joined: Fri Jan 28, 2022 6:09 pm

Page numbers are not right-aligned, header line not shown

Post by MjK »

dmarc wrote:I wanted to use the label at first to be able to jump directly to the point in the PDF.
\phantomsection in the hyperref manual.
My main topics are KOMA-Script and other questions related to my packages. If I reply to any other topic or if you've not yet added a minimal working example, please do not expect any further response. And please don't forget to tag examples as code.
Post Reply