5

After going through some of the forum posts on custom headings and bad section breaks I am still unable to eliminate the later.

I have customized my own Chapter and Section which generates "lonely" section headings (check out the MWE). I am certain that it is done wrong. Can anyone put me on the right track?

\documentclass{book}
\usepackage{fourier-orns}

\makeatletter
%%%SECTION%%%
\def\section{\MySection}
\def\MySection#1{
    \vskip 3ex \goodbreak
    \begingroup
        \noindent
            \Large\textbf{\S\thesection$\;$\textsc{#1}}\vspace{-.5\baselineskip}\par
        \noindent
    \endgroup
    \vskip 2\baselineskip %\goodbreak
}

%%%CHAPTER%%%
\def\@makechapterhead#1{
    \vspace*{\baselineskip}
    \begin{center}
        {\large\sc{Chapter \thechapter}}
        \par
        \noindent{\centering ------\large\decoone------}

        {\huge \strut{\sc{#1}}\strut \par}
    \end{center}
    \vskip 70\p@
}
\makeatother

\begin{document}
    \chapter{Top level}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam facilisis massa vel lacus varius dapibus. Pellentesque volutpat, tortor mattis eleifend euismod, tellus risus imperdiet dolor, id lobortis eros mi quis augue. Vestibulum eleifend congue orci id sollicitudin. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut non suscipit libero, ornare rutrum augue. Suspendisse tortor elit, sagittis quis porttitor nec, hendrerit eu velit. Aenean lacinia diam vel dui pulvinar placerat. In eget purus velit.

Cras hendrerit euismod justo ut tincidunt. Etiam ultrices, urna quis dapibus elementum, risus quam ornare nibh, nec fringilla lectus lectus in massa. Proin suscipit auctor tempor. Pellentesque elit dolor, tincidunt ut tellus eu, eleifend tristique odio. Nulla suscipit, lectus quis sollicitudin volutpat, ligula sem feugiat velit, id aliquam nunc metus at metus. Cras a libero dignissim, convallis dui et, hendrerit tellus. In tempor, nisl facilisis adipiscing consectetur, diam diam mattis nisi, ornare facilisis risus quam a sem. Etiam vel sapien in dui feugiat bibendum. Phasellus eget felis ut eros porta venenatis vel vitae ipsum.

Sed eu urna auctor, condimentum nisi id, posuere mauris. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas eu rhoncus quam. Fusce suscipit posuere eros, sit amet laoreet nunc pellentesque ut. Suspendisse augue quam, fermentum vitae porttitor sed, mollis eu lectus. Nam ut iaculis nibh. In aliquam metus in nibh vulputate, dignissim hendrerit tellus elementum. Morbi luctus diam vel leo semper ullamcorper. Maecenas enim eros, molestie vel lorem id, sodales cursus urna. Nunc commodo dolor massa, ac aliquam orci volutpat ut. Cras lacinia tincidunt sem sit amet lacinia. Maecenas malesuada nulla sem, at dignissim lorem ornare sed. Vestibulum et lorem lacinia, elementum quam ullamcorper, fermentum ligula. Donec et dictum magna, quis pulvinar nibh. et lorem lacinia, elementum quam ullamcorper, fermentum ligula. Donec et dictum magna, quis pulvinar nibh. et lorem lacinia, elementum quam ullamcorper, fermentum ligula. Donec et dictum magna, quis pulvinar nibh.

\section{Bad Break}
Maecenas enim eros, molestie vel lorem id, sodales cursus urna. Nunc commodo dolor massa, ac aliquam orci volutpat ut. Cras lacinia tincidunt sem sit amet lacinia. Maecenas malesuada nulla sem, at dignissim lorem ornare sed. Vestibulum et lorem lacinia, elementum quam ullamcorper, fermentum ligula. Donec et dictum magna, quis pulvinar nibh


\end{document}

(Also, as a side note, how do you get compiled Latex to render here?)

  • 2
    have you looked at trying this using a package- perhaps titlesec? or are you after a 'pure' way? – cmhughes Jul 29 '13 at 16:11
  • The less packages I call the better. – vrbatim Jul 29 '13 at 17:18
7

Classes use \@startsection for setting titles, which ensures that no page break will take place between the title and the text.

Here's an implementation with titlesec that internally uses the same mechanism.

\documentclass{book}
\usepackage{fourier-orns}
\usepackage{titlesec}

\titleformat{\chapter}[display]
 {\filcenter}
 {\large\scshape\chaptername\ \thechapter\\
  ---\negthinspace---\decoone---\negthinspace---}
 {0pt}
 {\huge}
\titlespacing*{\chapter}{0pt}{12pt}{70pt}

\titleformat{\section}[hang]
 {\Large\bfseries}
 {\S\thesection\ }
 {0pt}
 {}
\titlespacing*{\section}
  {0pt}
  {3.5ex plus 1ex minus .2ex}
  {1ex}

\begin{document}
\chapter{Top level}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam facilisis massa vel lacus 
varius dapibus. Pellentesque volutpat, tortor mattis eleifend euismod, tellus risus 
imperdiet dolor, id lobortis eros mi quis augue. Vestibulum eleifend congue orci id 
sollicitudin. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut non 
suscipit libero, ornare rutrum augue. Suspendisse tortor elit, sagittis quis porttitor 
nec, hendrerit eu velit. Aenean lacinia diam vel dui pulvinar placerat. In eget purus 
velit.

Cras hendrerit euismod justo ut tincidunt. Etiam ultrices, urna quis dapibus elementum, 
risus quam ornare nibh, nec fringilla lectus lectus in massa. Proin suscipit auctor 
tempor. Pellentesque elit dolor, tincidunt ut tellus eu, eleifend tristique odio. Nulla 
suscipit, lectus quis sollicitudin volutpat, ligula sem feugiat velit, id aliquam nunc 
metus at metus. Cras a libero dignissim, convallis dui et, hendrerit tellus. In tempor, 
nisl facilisis adipiscing consectetur, diam diam mattis nisi, ornare facilisis risus quam 
a sem. Etiam vel sapien in dui feugiat bibendum. Phasellus eget felis ut eros porta 
venenatis vel vitae ipsum.

Sed eu urna auctor, condimentum nisi id, posuere mauris. Class aptent taciti sociosqu ad 
litora torquent per conubia nostra, per inceptos himenaeos. Maecenas eu rhoncus quam. 
Fusce suscipit posuere eros, sit amet laoreet nunc pellentesque ut. Suspendisse augue 
quam, fermentum vitae porttitor sed, mollis eu lectus. Nam ut iaculis nibh. In aliquam 
metus in nibh vulputate, dignissim hendrerit tellus elementum. Morbi luctus diam vel leo 
semper ullamcorper. Maecenas enim eros, molestie vel lorem id, sodales cursus urna. Nunc 
commodo dolor massa, ac aliquam orci volutpat ut. Cras lacinia tincidunt sem sit amet 
lacinia. Maecenas malesuada nulla sem, at dignissim lorem ornare sed. Vestibulum et lorem 
lacinia, elementum quam ullamcorper, fermentum ligula. Donec et dictum magna, quis 
pulvinar nibh. et lorem lacinia, elementum quam ullamcorper, fermentum ligula. Donec et 
dictum magna, quis pulvinar nibh. et lorem lacinia, elementum quam ullamcorper, fermentum 
ligula. Donec et dictum magna, quis pulvinar nibh.

\section{Bad Break}

Maecenas enim eros, molestie vel lorem id, sodales cursus urna. Nunc commodo dolor massa, 
ac aliquam orci volutpat ut. Cras lacinia tincidunt sem sit amet lacinia. Maecenas 
malesuada nulla sem, at dignissim lorem ornare sed. Vestibulum et lorem lacinia, elementum 
quam ullamcorper, fermentum ligula. Donec et dictum magna, quis pulvinar nibh


\end{document}

You'll see that the section number is correct and that the page break happens before the title. Of course, this has the consequence that the paragraphs in the chapter starting page are spread out. Such problems should be addressed in the last revision of the document.

enter image description here


enter image description here


Note that very few font families have bold face small caps. In general there's no need for “double emphasis”: choose between small caps and boldface.

  • I like the design below chapter head :-) – Jagath Jul 29 '13 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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