Page Layout ⇒ Multi-line (section) headers?
Multi-line (section) headers?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Multi-line (section) headers?
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¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Multi-line (section) headers?
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?
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}