Featured Book

LaTeX Beginners Guide

Who is online

In total there are 12 users online :: 0 registered, 0 hidden and 12 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 12 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Add a horizontal Line in the Header

Add tags Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).

Add a horizontal Line in the Header

Postby Cham on Tue Jun 28th, 2011

I'm currently using the "book" document class (the document is a huge book of about 900 pages), and the chapter/section titles and page number are showing in the header, which is what I want.

However, I would like to add a simple horizontal line, as what we have under the "paper" document class. How can I do that ?
Last edited by Cham on Wed Jun 29th, 2011, edited 3 times in total.
User avatar
Cham
 
Posts: 378
Joined: Sat Apr 2nd, 2011

Re: Add a horizontal Line in the Header

Postby localghost on Tue Jun 28th, 2011

This is usually done by packages like fancyhdr or titlesec. The below example uses the latter one because it is capable of much more things than only page styles.
Code: Select all  •  Open in writeLaTeX
\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
}

You can additionally declare other page styles for front and back matter of your book. That's up to you. For details see the package manual.

As always, the blindtext package is only for creating dummy text, thus not part of the solution.


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Add a horizontal Line in the Header

Postby Cham on Tue Jun 28th, 2011

localghost wrote:The below example uses the latter one because it is capable of much more things than only page styles.
...


Cool ! It works (however, it clashed with my previous \pagestyle{headings} command).

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  •  Open in writeLaTeX
\usepackage[]{titlesec}
\newpagestyle{main
}{%
  \sethead[\thepage][][\chaptername\ \thechapter. \chaptertitle]{\thesection\ \sectiontitle}{}{\thepage}
  \headrule
}


EDIT : Ok, I've found a solution to the previous question. But is this the proper way to do this ?
Code: Select all  •  Open in writeLaTeX
\usepackage[]{titlesec}
\newpagestyle{main
}{%
  \sethead[\thepage][][\chaptername\ \textbf{\thechapter}. \textsc{\chaptertitle}]{\thesection\ \textsc{\sectiontitle}}{}{\thepage}
  \headrule
}
User avatar
Cham
 
Posts: 378
Joined: Sat Apr 2nd, 2011

Re: Add a horizontal Line in the Header

Postby localghost on Tue Jun 28th, 2011

Actually the headers by default are completely in capitals. But that's the advantage of using this package. You can easily customize the settings. Your code looks OK, although the header now looks a bit intrusive.
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Add a horizontal Line in the Header

Postby Cham on Tue Jun 28th, 2011

localghost wrote:Actually the headers by default are completely in capitals. ... Your code looks OK, although the header now looks a bit intrusive.


Intrusive ? What do you mean ?

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)
User avatar
Cham
 
Posts: 378
Joined: Sat Apr 2nd, 2011

Re: Add a horizontal Line in the Header

Postby localghost on Tue Jun 28th, 2011

Cham wrote:Intrusive ? What do you mean ? […]

It's a bit overdone. The header shall not catch one's eye too much.
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)

To mimic the default style, you can use the well known commands to control font styles. See the below example.
Code: Select all  •  Open in writeLaTeX
\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
}
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Add a horizontal Line in the Header

Postby Cham on Tue Jun 28th, 2011

localghost wrote:To mimic the default style, you can use the well known commands to control font styles. See the below example.


This works.

However, I noticed that there are chapters numbers 0.0 and wrong titles appearing in the header, for the frontmatter and backmatter parts.
User avatar
Cham
 
Posts: 378
Joined: Sat Apr 2nd, 2011

Re: Add a horizontal Line in the Header

Postby Cham on Wed Jun 29th, 2011

Okay, I think I have it right. Some parts of the code above don't go into the preamble. It must be placed AFTER the \mainmatter statement, and BEFORE the \backmatter. After the \backmatter command, I need to add \pagestyle{headings} to revert to the default style.

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  •  Open in writeLaTeX
\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
}
User avatar
Cham
 
Posts: 378
Joined: Sat Apr 2nd, 2011

Re: Add a horizontal Line in the Header

Postby localghost on Wed Jun 29th, 2011

You're quite close. Instead of using the »headings« page style I would declare new page styles for front, main and back matter. Take a look at the below example
Code: Select all  •  Open in writeLaTeX
\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
}

Note that the page styles »front« and »back« are the same. They have been declared in the sense of logical mark-up. This way it will be easier to modify to one of them (if desired).
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

Re: Add a horizontal Line in the Header

Postby Cham on Wed Jun 29th, 2011

Thanks a lot for your precious help ! :)
User avatar
Cham
 
Posts: 378
Joined: Sat Apr 2nd, 2011


Return to Page Layout

Who is online

Users browsing this forum: No registered users and 12 guests