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.

In short:

  • Prerequisite: Need to emulate book-class for \part and \chapter using titlesec
  • Change both to hang, start on same page
  • Add titlerule to \chapter

I want to optimize my rather hacked template.

First, as it isn't possible to do the changes below using titlesec without defining the sectioning title/head as a whole, I need it to be exactly like predefined by the standard book-class. That needs to be the starting point.

Then I want to use titlesec to make \part and \chapter "hanged" (like \titleformat{\part}[hang]) and on the same page with the following chaptertext:

Not this:

      Part A     
     Parttitle

-------newpage--------
Chapter 1

Chaptertitle

but this:

A Parttitle

1 Chaptertitle

At last I need to replace the following newcommand

\newcommand{\addchapterunderline}{\vspace{-4ex}\hrule height 1.5pt \vspace{7ex}\thispagestyle{empty}}

for \chapter AND \chapter*, wich I utilized like this until now:

\chapter[Test]{Test}
\addchapterunderline

The final structure should look like this using \titlerule[1.5pt]:

A Parttitle

B Chaptertitle
________________________

Lorem ipsum ...

In this example I already tried my best (<-- still beginner). But I cannot prove whether this is book-class-like with only my changes above, as I could not find the heading-definitions in the book.cls:

\documentclass{book}

        \usepackage[ngerman]{babel}             
        \usepackage[T1]{fontenc}
        \usepackage{lmodern}
        \usepackage[ansinew]{inputenc}      
        \usepackage{tgheros}                            
        \usepackage[expert]{mathdesign}     
        \usepackage{amssymb}                            
        \usepackage{ae,aecompl}                     
        \usepackage{charter}                            

%\newcommand{\addchapterunderline}{\vspace{-4ex}\hrule height 1.5pt \vspace{7ex}\thispagestyle{empty}} %I don't want to use this

\usepackage{titlesec}

\titleclass{\part}{top}
\titleformat{\part}[hang]
  {\usefont{T1}{qhv}{b}{n}\selectfont\huge} % global formatting (number and title) 
    {\thepart} 
    {20pt} %spacing between number and title
    {\huge}
\titlespacing*{\part}
   {0pt}% left
   {1cm}% before
   {1.2em}% after
\titleclass{\chapter}{straight}
\titleformat{\chapter}[hang]
  {\usefont{T1}{qhv}{b}{n}\selectfont\huge} % global formatting (number and title)
    {\thechapter}  % label: number and its formatting
    {20pt} %spacing between number and title
    {\huge}[\vspace{2ex}{\titlerule[1.5pt]}]
\titlespacing*{\chapter}
   {0pt}% left
   {1cm}% before
   {6.2em}% after



\begin{document}
\part{This is a Testpart}
\chapter{This is a Testchapter}
\chapter*{This is a unnumbered Testchapter}
\end{document}
share|improve this question
1  
Section 9.2 of the titlesec manual shows how to emulate the sectioning commands of the standard classes. –  lockstep Mar 7 '13 at 20:13
    
Really helpful, but the definition for \part is missing. Where can I find this? –  FLW Mar 7 '13 at 20:52
    
Sadly, I don't know. –  lockstep Mar 7 '13 at 20:54
    
And what should happen with other chapters of the same part? Should the same formatting also apply to them? I mean, chapter two of the first part should have the title immediately after the end of chapter one without issuing the default \cleardoublepage? –  Gonzalo Medina Mar 7 '13 at 21:45
    
No, @Gonzalo, of course I manually add \newpage{\thispagestyle{plain}\cleardoublepage} after every chapter. –  FLW Mar 7 '13 at 21:52
show 2 more comments

1 Answer 1

up vote 6 down vote accepted

There's no information on the formatting for other chapters in the same part, so I assumed they should all have the same behaviour (in particular, they should not start on a new odd page); there was also no information on the vertical space before part titles, so I assumed some settings (which can be easily changed, if necessary). Here's one possibility:

\documentclass{book}
\usepackage{titlesec}

\renewcommand\thepart{\Alph{part}}
\titleclass{\part}{top}
\titleclass{\chapter}{straight}

\titleformat{\part}[hang]
  {\normalfont\huge\bfseries}{\thepart}
  {1em}{\Huge}
\titleformat{\chapter}[hang]
  {\normalfont\huge\bfseries}{\thechapter}
  {1em}{\Huge}[\vskip8pt{\titlerule[1.5pt]}]

\titlespacing*{\part}
  {0pt}{50pt}{40pt}
\titlespacing*{\chapter}
  {0pt}{0pt}{20pt}

\begin{document}

\part{Test Part One}
\chapter{Test Chapter One}

\end{document}

enter image description here

After a comment to the original question, only the first chapter should have the mentioned behaviour; other chapters of a same part should issue the standard \cleardoublepage command from book.cls; this can be automatically achieved using a conditional test and the etoolbox package:

\documentclass{book}
\usepackage{titlesec}
\usepackage{etoolbox}

\renewcommand\thepart{\Alph{part}}
\titleclass{\part}{top}
\titleclass{\chapter}{straight}

\titleformat{\part}[hang]
  {\normalfont\huge\bfseries\raggedright}{\thepart}
  {1em}{\Huge}
\titleformat{\chapter}[hang]
  {\normalfont\huge\bfseries\raggedright}{\thechapter}
  {1em}{\Huge}[\vskip8pt{\titlerule[1.5pt]}]

\titlespacing*{\part}
  {0pt}{50pt}{40pt}
\titlespacing*{\chapter}
  {0pt}{0pt}{20pt}

\pretocmd{\chapter}{\ifnum\value{chapter}>0 \newpage\thispagestyle{plain}\cleardoublepage\else\fi}{}{}{}

\begin{document}

\part{Charakterisierung des französischen Automobilwesens in Berlin} \chapter{Charakterisierung des französischen Automobilwesens in Berlin} \chapter{Charakterisierung des französischen Automobilwesens in Berlin}

\end{document}

An image of the first page containing the part title:

enter image description here

share|improve this answer
    
Yes, this is it. But now I encounter overfull lines: !prob –  FLW Mar 7 '13 at 22:35
    
@FLW are those overfull lines directly related to the titles? If so, I would need to see a simple document using my code and producing the problem mentioned. –  Gonzalo Medina Mar 7 '13 at 22:46
    
Please use this in your example above to reproduce: \part{Charakterisierung des französischen Automobilwesens in Berlin} \chapter{Charakterisierung des französischen Automobilwesens in Berlin} \chapter{Charakterisierung des französischen Automobilwesens in Berlin} –  FLW Mar 7 '13 at 23:12
1  
@FLW you can then use \raggedright as I did in my updated answer; this will also prevent hyphenations, which don't look good in titles. –  Gonzalo Medina Mar 7 '13 at 23:19
    
Works great. Regarding your \pretocmd{\chapter}{\ifnum\value{chapter}>0 \newpage\thispagestyle{plain}\cleardoublepage\else\fi}{}{}{} I had to use my old solution because \part was on its own page again using your solution. But that is ok. Thanks again. –  FLW Mar 7 '13 at 23:48
add comment

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.