Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to left or right align my chapter number, and center the chapter title on the next page. I've used the \titlesec package, but it removes the header and footer on the first page of every chapter. The code I've written right aligns both the chapter number and the title. Is there any workaround?

\documentclass{report}

\usepackage{fancyhdr}
\usepackage{titlesec}

\titleformat{\chapter}[display]
{\normalfont\Large\bfseries\raggedleft}{\chaptertitlename\ \thechapter}
{20pt}{\Large}
\pagestyle{fancy}

\rhead{XYZ}

\lhead{year}

\lfoot{Blah}

\cfoot{}

\rfoot{\thepage}

\begin{document}

\chapter{Title}
Test
\end{document}
share|improve this question
    
So you're interested in achieving 2 goals: (1) Headers/footers on your first page of chapter; and (2) a left/right alignment of chapter title+number. I'm not clear on exactly what (2) refers to. Could you elaborate? –  Werner May 7 '13 at 18:59
    
If I'm having a chapter titled Introduction, and it is the first chapter, I'd like chapter 1 to be aligned to the left or right, and I'd like Introduction to be centered on the next line following the chapter number. –  user1556826 May 7 '13 at 19:20

1 Answer 1

up vote 1 down vote accepted

To have the header/footer in the first page of every chapter, you can patch (with the help of, for example, etoolbox package) the \chapter command to change the default plain style for fancy.

To have the chapter name+chapter number right (left aligned) you can use \filright (\filleft, respectively) in the second argument for \titleformat and then \filcenter in the fifth argument to have the title centered;

\documentclass{report}
\usepackage[a5paper,showframe]{geometry}% just for the example
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{etoolbox}
\usepackage{lipsum}% just to generate text for the example

\titleformat{\chapter}[display]
  {\normalfont\Large\bfseries}{\filleft\chaptertitlename\ \thechapter}
  {20pt}{\Large\filcenter}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{XYZ}
\fancyhead[L]{year}
\fancyfoot[L]{Blah}
\fancyfoot[R]{\thepage}

\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

\begin{document}

\chapter{Test Title}
\lipsum[1-5]

\end{document}

enter image description here

I used the geometry package with its showframe option just to have a visual guideline.

share|improve this answer
    
That was exactly what I needed. Thank you!! –  user1556826 May 7 '13 at 19:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.