Document Classesheaders with titlesec

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
iperten
Posts: 40
Joined: Thu Jul 12, 2007 1:53 pm

headers with titlesec

Post by iperten »

Dear all,

I am writing a report and I'm using the titlesec for the headers.

This the code I use:

Code: Select all

\renewpagestyle{plain}[\small\sffamily\upshape]{
  \footrule
  \setfoot{}{\textbf{\thepage}}{}}
\newpagestyle{myps}[\small\sffamily\upshape]{
  \headrule
  \sethead[\textbf{\thepage}][][\textbf{\thechapter.  \chaptertitle}]
          {\textbf{\thesection. \sectiontitle}}{}{\textbf{\thepage}}}
\pagestyle{myps}
As you can see, on even pages I print the number and title of the chapters, while on odd pages I print the number and the title of the section.

Now, if a chapter, like the introduction or the bibliography, does not have any section, on the odd pages nothing comes out, but of course in such cases I'd like the number and title of the chapter as well.

How can I solve the problem?

Thank you, cheers, Mattia.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

headers with titlesec

Post by localghost »

The great advantage of [url=htpp://ctan.org/pkg/titlesec]titlesec[/url] regarding page styles is the fact that you can define more than only one style. So you could declare a style especially for those chapters without sections and switch between the others. Take this as an example.

Code: Select all

\newpagestyle{nosecs}[\small\sffamily\upshape]{
  \headrule
  \sethead[\textbf{\thepage}][][\textbf{\thechapter. \chaptertitle}]
          {\textbf{\thechapter. \chaptertitle}}{}{\textbf{\thepage}}
}
I simply copied the contents of the right head on even pages to left head of odd pages. For your introduction and bibliography you now can switch to that page style to get the chapter in the head of both pages.


Best regards
Thorsten¹
iperten
Posts: 40
Joined: Thu Jul 12, 2007 1:53 pm

Re: headers with titlesec

Post by iperten »

Thanks a lot!

But now the following question: where should I place the commands?

I tried to write them right after the others and the results is that everything is now affected with that page style.

I put them at the end, right after the command to insert the bibliography, and it did not work either.

Thank you!

Cheers,
M.

PS: I am using the book class... I don't know if this info can help as well.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

headers with titlesec

Post by localghost »

iperten wrote:[...] But now the following question: where should I place the commands? [...]
Of course this declaration goes into the preamble. To activate this page style, use the usual command.

Code: Select all

\pagestyle{nosecs}
This should work when inserted right before the bibliography. The page style remains activated until you switch to another one.
iperten
Posts: 40
Joined: Thu Jul 12, 2007 1:53 pm

Re: headers with titlesec

Post by iperten »

Ja, it works! :)

Thanks a lot!

Cheers,
M.
Post Reply