Page Layout ⇒ Multi-line (section) headers?
Multi-line (section) headers?
I'm having a bit of trouble with some of my section headers. A lot of them are very long, and as a result get pushed over the margins, also moving the page number. I have a line break(\\) in them anyway, because I want part of the section names to be on new lines both at the section title, and in the table of contents. Unfortunately this doesn't work for the headers. Is there any way I can get my headers to be multi-line so that the part after the line break goes on its own line in the header? I'm using the book class, double-sided if this helps. Thanks.
- localghost
- Site Moderator
- Posts: 9201
- Joined: Fri Feb 02, 2007 12:06 pm
Multi-line (section) headers?
I can't comprehend the problem with the line breaks.
Regarding the header I recommend to choose the short form option for the sectioning commands.
It would be much better to show your problems by means of a minimal working example (MWE) which shall be small, complete and compilable.
Best regards and welcome to the board
Thorsten¹
Code: Select all
\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\chapter{A long chapter title only chosen to demonstrate a line break that shouldn't go into the margin}
\blindtext
\section{A long section title only chosen to demonstrate a line break that shouldn't go into the margin}
\blindtext
\end{document}
It would be much better to show your problems by means of a minimal working example (MWE) which shall be small, complete and compilable.
Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Board Rules
Avoidable Mistakes[/size]
¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Multi-line (section) headers?
What I have now is like the following (I have set it as A5 to make the problem more obvious):
Which in my ToC and at the location in the document where the section name is printed gives me:
Code: Select all
\documentclass[a5paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{blindtext}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}
\begin{document}
\tableofcontents
\chapter{This is an example chapter}
\section{This is an example section with a long name\\(and this is text I want to go below)}
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\end{document}
Which is what I want. However, with my header it gives me:This is an example section with a long name
(and this is text I want to go below)
which is unacceptable because it runs right across the page. I want the header of the pages to be like it is in the ToC and at the location in the document (i.e. I want it to have a line break in it).This is an example section with a long name(and this is text I want to go below)
Multi-line (section) headers?
You may consider using fancyhdr package for setting headers and footers easy way. Here's an example (your code, slightly changed):
But still, two lines in headers look, ehm, strange at least.
Code: Select all
\documentclass[a4paper,english]{book}% Set a4paper
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage{blindtext}
\usepackage{babel}
\usepackage{fancyhdr}% fancyhdr related command; details in its documentation
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}
\begin{document}
\tableofcontents
\chapter{This is an example chapter}
\section{This is an example section with a long name\\(and this is text I want to go below)}
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\end{document}
Re: Multi-line (section) headers?
That's great thanks! There were a few things I wanted to change in the headers actually, but I didn't think fancyhdr would do that as well. Thanks!