Page Layout ⇒ Add a horizontal Line in the Header
Add a horizontal Line in the Header
However, I would like to add a simple horizontal line, as what we have under the "paper" document class. How can I do that ?
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
Add a horizontal Line in the Header
Code: Select all
\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}
\newpagestyle{main}{%
\sethead[\thepage][][\chaptername\ \thechapter. \chaptertitle]{\thesection\ \sectiontitle}{}{\thepage}
\headrule
}
\pagestyle{main}
\begin{document}
\blinddocument
\end{document}
As always, the blindtext package is only for creating dummy text, thus not part of the solution.
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Add a horizontal Line in the Header
Cool ! It works (however, it clashed with my previous \pagestyle{headings} command).localghost wrote:The below example uses the latter one because it is capable of much more things than only page styles.
...
However, the header's titles aren't in small caps. How should I modify the following code to make all header's titles in small caps ?
Code: Select all
\usepackage[]{titlesec}
\newpagestyle{main}{%
\sethead[\thepage][][\chaptername\ \thechapter. \chaptertitle]{\thesection\ \sectiontitle}{}{\thepage}
\headrule
}
Code: Select all
\usepackage[]{titlesec}
\newpagestyle{main}{%
\sethead[\thepage][][\chaptername\ \textbf{\thechapter}. \textsc{\chaptertitle}]{\thesection\ \textsc{\sectiontitle}}{}{\thepage}
\headrule
}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: Add a horizontal Line in the Header
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Add a horizontal Line in the Header
Intrusive ? What do you mean ?localghost wrote:Actually the headers by default are completely in capitals. ... Your code looks OK, although the header now looks a bit intrusive.
Without the styles in my modification, the code gives simple lowecase titles. How can I make the title in slanted capitals ? (that was the default style with the default book documentclass)
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Add a horizontal Line in the Header
It's a bit overdone. The header shall not catch one's eye too much.Cham wrote:Intrusive ? What do you mean ? […]
To mimic the default style, you can use the well known commands to control font styles. See the below example.Cham wrote:[…] Without the styles in my modification, the code gives simple lowercase titles. How can I make the title in slanted capitals ? (that was the default style with the default book documentclass)
Code: Select all
\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}
\newpagestyle{main}{%
\sethead[\thepage][][\itshape\MakeUppercase{\chaptername\ \thechapter. \chaptertitle}]{\itshape\MakeUppercase{\thesection\ \sectiontitle}}{}{\thepage}
\headrule
}
\pagestyle{main}
\begin{document}
\blinddocument
\end{document}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Add a horizontal Line in the Header
This works.localghost wrote: To mimic the default style, you can use the well known commands to control font styles. See the below example.
However, I noticed that there are chapters numbers 0.0 and wrong titles appearing in the header, for the frontmatter and backmatter parts.
Add a horizontal Line in the Header
Is that right ? I need a confirmation because I don't want to built a whole sand castle of missplaced commands. After a while, the document may turn into a commands mess !
Please, can you check the structure of the following code, just to confirm that everything is properly done ?
Code: Select all
\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[]{titlesec}
\raggedbottom
\usepackage[bottom]{footmisc}
\pagestyle{headings}
%%%% End of preamble
\begin{document}
\frontmatter
\thispagestyle{empty}
\newpage
\tableofcontents
\mainmatter
\newpagestyle{main}{
\sethead[\thepage][][\itshape\MakeUppercase{\chaptername\ \thechapter. \chaptertitle}]{\itshape\MakeUppercase{\thesection\ \sectiontitle}}{}{\thepage}
\headrule
}
\pagestyle{main}
\input{Chapitre1}
\input{Chapitre2}
\backmatter
\pagestyle{headings}
\appendix
\begin{thebibliography}{999}
\input{Bibliographie}
\end{thebibliography}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Add a horizontal Line in the Header
Code: Select all
\documentclass[12pt,english]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}
\newpagestyle{front}{%
\sethead[\thepage][][\itshape\MakeUppercase{\chaptertitle}]{\itshape\MakeUppercase{\sectiontitle}}{}{\thepage}
\headrule
}
\newpagestyle{main}{%
\sethead[\thepage][][\itshape\MakeUppercase{\chaptername\ \thechapter. \chaptertitle}]{\itshape\MakeUppercase{\thesection\ \sectiontitle}}{}{\thepage}
\headrule
}
\newpagestyle{back}{%
\sethead[\thepage][][\itshape\MakeUppercase{\chaptertitle}]{\itshape\MakeUppercase{\sectiontitle}}{}{\thepage}
\headrule
}
\begin{document}
\frontmatter
\pagestyle{front}
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\pagestyle{main}
\blinddocument
\backmatter
\pagestyle{back}
\begin{thebibliography}{99}
\bibitem{key} Bibliography Item
\end{thebibliography}
\end{document}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Add a horizontal Line in the Header
