I am using the book class to write a document that will have numbered paragraphs. Wanted the (auto-incremented) paragraph numbers to be bold and centred, then the text below, and the paragraph number to have a label so it can be referenced. Using other people's suggestions, I've got this function/command:
\newcounter{para}
\newcommand\mypara[1]{
\par\refstepcounter{para}\vfill
\begin{center}\textbf{\thepara}\end{center}\label{#1}
}
and the way I use it in the document is:
\mypara{myreference}
This is a nice numbered paragraph. I don't want any braces around the paragraph body, if at all possible.
which is working nicely EXCEPT when I use it close to the bottom of the page, in which case it's possible for the bold paragraph number to be on one page, and the text of the paragraph to be on the next. Is it possible to prevent a page break like this? I'm using multicols{2} as well, if that's relevant. Any help appreciated.
Min. example:
\documentclass[10pt]{book}
\usepackage{multicol}
\setlength\columnsep{1cm} % sets the distance between columns
\usepackage{blindtext}
\newcounter{para}
\newcommand\mypara[1]{
\par\refstepcounter{para}\vfill
\begin{center}\textbf{\thepara}\end{center}\label{#1}
}
\title{Minimum working example}
\begin{document}
\pagestyle{empty}
% main part of the document:
\mainmatter
\begin{multicols}{2}
\mypara{ref1}
\blindtext
\mypara{ref2}
\blindtext
\mypara{ref3}
\blindtext
\mypara{ref4}
\blindtext
\end{multicols}
\end{document}
\label{#1}
to also include something that will help you with easy identification? For example\label{par:#1}
. This will help if you ever have a chapter and a paragraph with the same name, but need to reference both on separate occasions.\vfill
? Since removing it results in this, which looks better IMO.\vfill
put the whole stuff in a box, eg.g., a\parbox
or aminipage
, or to use other that an invisible unbreakable box, maybe you would like the tcolorbox package (that can numbered and referenced, among a lot of another features, it have an excellent manual) but personally I will use sections as in the Jhor's answers.