Page Layout ⇒ fancyhdr | Problem with Sections in Header
-
- Posts: 5
- Joined: Tue Feb 14, 2012 6:43 pm
fancyhdr | Problem with Sections in Header
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Problem with Sections in Header
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 5
- Joined: Tue Feb 14, 2012 6:43 pm
fancyhdr | Problem with Sections in Header
Here is the code. I think the problem lies in the re-definition of the section, but I have no idea how to solve it. In the header on the last page, it doesn't say "Short title of sec" but puts a dot in front of it so it reads ". Short title of sec". Any help is much appreciated
Code: Select all
\documentclass{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RO,LE]{\leftmark}
\fancyhead[RE,LO]{\rightmark}
\fancyfoot[LE,RO]{\thepage}
\fancyfoot[RE,LO]{}
\cfoot{}
\renewcommand\thesection{\hspace{-1em}}
\begin{document}
\begin{titlepage}
\Huge {\bf The Title}
\end{titlepage}
\setcounter{tocdepth}{2}
\tableofcontents
\chapter{One}
\section[Short title of sec]{Long title of section}
And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times. And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.And here there is some text, which should be long enough to fill an entire page, hence I repeat it several times.
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Problem with Sections in Header
Code: Select all
\renewcommand{\thesection}{\hspace{-1em}}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 5
- Joined: Tue Feb 14, 2012 6:43 pm
Re: fancyhdr | Problem with Sections in Header
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: fancyhdr | Problem with Sections in Header
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 5
- Joined: Tue Feb 14, 2012 6:43 pm
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
fancyhdr | Problem with Sections in Header
Code: Select all
\documentclass{book}
\usepackage{fancyhdr}
\usepackage{lipsum}
\fancyhf{}
\fancyhead[RO,LE]{\leftmark}
\fancyhead[RE,LO]{\rightmark}
\fancyfoot[LE,RO]{\thepage}
\pagestyle{fancy}
\setcounter{secnumdepth}{0} % default value 2 for »book« class
\setcounter{tocdepth}{2}
\begin{document}
\tableofcontents
\chapter{One}
\section[Short title of Section]{Long title of Section}
\lipsum
\end{document}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
-
- Posts: 5
- Joined: Tue Feb 14, 2012 6:43 pm