The correct way to perform a section break in LaTeX
Edit: I've put the package on Github and released it on CTAN.
I also added new package option asterism
and a new command \asterism
, which will print the asterism symbol.
You can try the following package, sectionbreak.sty
:
\ProvidesPackage{sectionbreak}
\usepackage{kvoptions}
\DeclareStringOption[2em]{preskip}
\DeclareStringOption[2em]{postskip}
\DeclareStringOption[\relax]{style}
\DeclareStringOption[~]{mark}
\ProcessKeyvalOptions*
\newcommand\pre@sectionbreak{\par\vskip\sectionbreak@preskip\relax}
\newcommand\post@sectionbreak{\par\vskip\sectionbreak@postskip\relax}
% print centered section break mark
\newcommand\print@sectionbreak[1]{%
\bgroup%
\noindent\null\hfill\sectionbreak@style\hbox{#1}\hfill\null\par%
\egroup%
}
% default section break mark is an unbreakable space
\newcommand\sectionbreak[1][\sectionbreak@mark]{%
\pre@sectionbreak%
\print@sectionbreak{#1}%
\post@sectionbreak%
}
\newcommand\sectionbreakmark[1]{%
\gdef\sectionbreak@mark{#1}%
}
\endinput
It provides a document command, \sectionbreak
. It has one optional argument, where you can specify characters which should be printed in the section break. For example, I've often seen ***
used in this context. Default section mark is a space, so it doesn't print anything.
It is possible to change the used characters using mark
option of the sectionbreak
package. If you want to use more complicated mark, like rule or image, you can use the \sectionbreakmark
command.
There are also options for dimensions which should be used for space before and after the mark, preskip
and postskip
. They are set to 2em
by default. The last option is style, you can set it for example to \bfseries
if you want the mark to be printed in the bold weight.
As you mentioned that you use tex4ebook
, you will also need to provide a configuration file for tex4ht
, because it would be translated insufficiently to HTML by default. It might look like this:
\NewConfigure{sectionbreak}{2}
\renewcommand\sectionbreak[1][\sectionbreak@mark]{%
\a:sectionbreak\bgroup\sectionbreak@style #1\egroup\b:sectionbreak%
}
\Configure{sectionbreak}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="sectionbreak">}}{\HCode{</div>}}
\Css{div.sectionbreak{
margin-top:3rem;
margin-bottom:3rem;
text-align:center;
}}
It declares new configuration hooks, sectionbreak
, which are then inserted to redefined \sectionbreak
command. The redefined command just inserts the HTML code configured in the hooks and the section break mark. The sectionbreak
is then configured to insert the <div class="sectionbreak">
element. Using CSS, we center the section mark and define some vertical space before and after mark.
It can be used like this:
\documentclass{article}
\usepackage[mark=***]{sectionbreak}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\sectionbreak[!!!]
\lipsum[5-7]
\sectionbreak
\lipsum[1-2]
\sectionbreakmark{\rule{10em}{3pt}}
\sectionbreak
\lipsum[6-8]
\end{document}
This is the resulting PDF with asterisk mark:
And this is the resulting HTML, again with asterisks (this example comes from the original answer, where asterisks were used after the first \lipsum
command, the correct marks are rendered in HTML as well):
<p class="indent" > Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at,
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam.
Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam
ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula
feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim.
Pellentesque tincidunt purus vel magna. Integer non enim. Praesent euismod nunc
eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus.
Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu
massa.
</p>
<div class="sectionbreak">***</div>
<!--l. 10--><p class="indent" > Fusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibus
semper, leo velit ultricies tellus, ac venenatis arcu wisi vel nisl. Vestibulum
diam. Aliquam pellentesque, augue quis sagittis posuere, turpis lacus congue
quam, in hendrerit risus eros eget felis. Maecenas eget erat in sapien mattis
porttitor. Vestibulum porttitor. Nulla facilisi. Sed a turpis eu lacus commodo
facilisis. Morbi fringilla, wisi in dignissim interdum, justo lectus sagittis
dui, et vehicula libero dui cursus dui. Mauris tempor ligula sed lacus. Duis
cursus enim ut augue. Cras ac magna. Cras nulla. Nulla egestas. Curabitur a
leo. Quisque egestas wisi eget nunc. Nam feugiat lacus vel est. Curabitur
consectetuer.
</p>
The memoir
class has various commands for producing what it calls "anonymous divisions". For example \plainbreak{2}
will produce 2 blank lines while \fancybreak{{*}\\{* * *}\\{*}}
typesets a centered little diamond made of asterisks. It also has commands to deal with the situation where, for example, blank lines are used in the middle of a page but something more indicative is need if the anonymous break occurs at the start or end of a page.
In my opinion it is always better to have some typographical marker for anonymous divisions (section breaks) rather than simply extra blank space.
Read the manual (texdoc memoir
) for more information.
You could insert an empty sectioning command (which one depends on the structure of your document):
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\section*{}
\lipsum[5-7]
\end{document}