Generaltitlesec | Header for Bibliography

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
olga30d
Posts: 8
Joined: Thu Jul 28, 2011 12:39 pm

titlesec | Header for Bibliography

Post by olga30d »

Dear all,

I have a problem with a header in my 'References' chapter - it has the header of the previous chapter.
I wonder if I can redefine it manually?
I have seen several similar problems, but unfortunately I did not manage to sort it out.

Many thanks,
Olga

Code: Select all

%%%%%%%%%%%%%%%%
\documentclass[11pt, oneside]{book}
\usepackage[pagestyles,raggedright]{titlesec}
\titleformat*{\section}{\LARGE\bfseries\rm} 
\titleformat*{\subsection}{\Large\bfseries\rm} 
\titleformat*{\subsubsection}{\large\bfseries\rm}
\newpagestyle{main}[\small\sffamily\rm]{
\headrule
\sethead{\thechapter\enspace\chaptertitle}{}{\thepage}} 
\begin{document}
\pagestyle{empty}
%some title
\pagestyle{main}
%\input{Chapter1} 
%\input{Chapter2} 
\bibliographystyle{apalike}  
\renewcommand\bibname{{References}}
\addcontentsline{toc}{chapter}{References}
\bibliography{MyReferences}  
\end{document}
Last edited by olga30d on Mon Aug 01, 2011 11:03 pm, edited 2 times in total.

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

titlesec | Header for Bibliography

Post by Stefan Kottwitz »

Hi Olga,

you could use \markboth, such as

Code: Select all

\cleardoublepage
\addcontentsline{toc}{chapter}{References}
\markboth{References}{References}
\bibliography{MyReferences}
Stefan
LaTeX.org admin
olga30d
Posts: 8
Joined: Thu Jul 28, 2011 12:39 pm

titlesec | Header for Bibliography

Post by olga30d »

Thanks Stefan,

I tried it in this order, but it did not work. Anything missing?
Many thanks,
Olga

Code: Select all

\bibliographystyle{apalike}
\cleardoublepage   
\addcontentsline{toc}{chapter}{References}   
\markboth{References}{References} 
\bibliography{MyReferences}  
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

titlesec | Header for Bibliography

Post by localghost »

You are already using the titlesec package. Just define a new page style with appropriate settings. The code below gives some inspiration.

Code: Select all

\begin{filecontents*}{\jobname.bib}
@BOOK{knuth84,
  author={Donald Ervin Knuth},
  title={The \TeX book},
  year={1984},
  publisher={Addison-Wesley}
}
@BOOK{lamport94,
  author={Leslie Lamport},
  title={\LaTeX\ -- A Document Preparation System},
  note={User's Guide and Reference Manual},
  year={1994},
  publisher={Addison-Wesley},
  edition={Second}
}
@BOOK{mitgoo04,
  author={Frank Mittelbach and Michel Goossens},
  title={The \LaTeX\ Companion},
  year={2004},
  publisher={Addison-Wesley},
  edition={Second}
}
@BOOK{goomit07,
  author={Michel Goossens and Frank Mittelbach and Sebastian Rahtz and Denis Roegel and Herbert Voss},
  title={The \LaTeX\ Graphics Companion},
  year={2007},
  publisher={Addison-Wesley},
  edition={Second}
}
\end{filecontents*}
\documentclass[11pt,oneside,english]{book}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage[nottoc]{tocbibind}
\usepackage{blindtext}

\renewcommand{\bibname}{References}

\titleformat*{\section}{\LARGE\bfseries\rmfamily}
\titleformat*{\subsection}{\Large\bfseries\rmfamily}
\titleformat*{\subsubsection}{\large\bfseries\rmfamily}

\newpagestyle{main}[\small\sffamily\rm]{%
  \headrule
  \sethead{\thechapter\enspace\chaptertitle}{}{\thepage}
}
\newpagestyle{back}[\small\sffamily\rm]{%
  \headrule
  \sethead{\chaptertitle}{}{\thepage}
}

\begin{document}
\pagestyle{main}
\blinddocument
\nocite{*}
\pagestyle{back}
\bibliographystyle{apalike} 
\bibliography{\jobname}
\newpage~
\end{document}
The same page style (named »front« for a more comprehensive view) is suggestive for the front matter part with ToC, LoF and LoT.

As always, the blindtext package is only for creating dummy text, thus it is not part of the solution. The tocbibind package generates an entry for the bibliography in ToC and is also not part of the solution but just a useful addition.


Thorsten
olga30d
Posts: 8
Joined: Thu Jul 28, 2011 12:39 pm

titlesec | Header for Bibliography

Post by olga30d »

Thanks Thorsten,

I definitely got some inspiration (as well as useful packages). After all, I had to move

Code: Select all

\renewcommand{\bibname}{References}
from preamble to the body of the document.
But I still could not get appropriate header, so I cheated a bit and used

Code: Select all

\newpagestyle{back}[\small\sffamily\rm]{%
  \headrule
  \sethead{References}{}{\thepage}
}  
Not sure why it does not work, I am using

Code: Select all

\usepackage[toc,titletoc,header]{appendix}
for my Appendices, maybe it clashes somehow.

So, I have solved my problem, maybe not as neat but it works. Thanks again to you and Stefan.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: titlesec | Header for Bibliography

Post by localghost »

Indeed not a neat solution. Did you test my suggestions? And if so, where are the problems? For me it works just fine.
olga30d
Posts: 8
Joined: Thu Jul 28, 2011 12:39 pm

Re: titlesec | Header for Bibliography

Post by olga30d »

I have tried your suggestions (well not exactly your example, but incorporated in my code) - and for some reason it had no effect on headers. To find out why, you probably need to analyse it (see attached).

Thanks!
Attachments
generic.tex
(4.75 KiB) Downloaded 249 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

titlesec | Header for Bibliography

Post by localghost »

The provided file is useless because it reads external files that are not present to others [1]. Reduce the problem to a true minimal example. But I guess that you better want to stay with your solution (because it's the shorter way).

[1] View topic: Avoidable mistakes
olga30d
Posts: 8
Joined: Thu Jul 28, 2011 12:39 pm

Re: titlesec | Header for Bibliography

Post by olga30d »

True, but I deliberately wanted to keep my file as it is and I was hoping that you would be able to pick up any inconsistencies just from looking at it.

Thanks for your help,

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

titlesec | Header for Bibliography

Post by localghost »

olga30d wrote:True, but I deliberately wanted to keep my file as it is and I was hoping that you would be able to pick up any inconsistencies just from looking at it. […]
Just looking at code is rarely successful. Testing is much more promising. And usually when building a MWE you should work with a copy of your document.
Post Reply