For a project, I have created a sectioning level called \numsubpara using an independent counter.
Unfortunately, quite often I get this situation :
I would like to avoid as much as possible this page break. In this case, I would like my title to be on the next page.
I know this feature exists with the usual \section, \subsection etc. But in this case, I cannot use these commands, I have to stick to my own command.
The document I am creating being quite long, it has to be automatic, i.e. I cannot manually add \pagebreak before lonely \numsubpara commands.
Does anyone know how to do this? Thank you in advance !
Here is my MWE :
\documentclass[12pt,twoside]{book}
\usepackage[paperheight=240mm,paperwidth=160mm, left=22mm, right = 20mm, top = 20mm, bottom = 22mm]{geometry}
\usepackage[cam,width=17.5truecm,height=25.54truecm,center,dvips,noinfo]{crop}
\usepackage[french]{babel}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{titlesec}
%\usepackage{needspace}
%\newcounter{subpara}
%\setcounter{subpara}{0}
%\newcommand\numsubpara[1]%
%{\vspace{3.36mm}\par\refstepcounter{subpara}%
%\needspace{2em}%
%\fontsize{10}{12}\selectfont\textbf{\thesubpara.}\fontsize{12}{12}\selectfont%
%\space\textbf{#1}\space\vspace{2.8mm}\\%
%\fontsize{12}{12}\selectfont\nobreak%
%}
\newcounter{subpara}
\setcounter{subpara}{0}
\newcommand\numsubpara[1]%
{\vspace{3.36mm}\par\refstepcounter{subpara}%
\fontsize{10}{12}\selectfont\textbf{\thesubpara.}\fontsize{12}{12}\selectfont%
\space\textbf{#1}\space\vspace{2.8mm}\\%
\fontsize{12}{12}\selectfont\nobreak%
}
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
\newcommand{\hnumsubpara}{\tocless\numsubpara}
\begin{document}
\chapter{Test}
\section{Test}
\hnumsubpara{Test}
\lipsum[1]
\hnumsubpara{My command\footnote{\lipsum[1]}}
\lipsum[1]
\tableofcontents
\end{document}

\titlespacingis way better than\vspace. Double thanks :). – Guliup May 22 '20 at 16:09\numsubparanot to be shown in the ToC. It seems that in this case it is appearing, do you know how to avoid this ? Thank you ! – Guliup May 22 '20 at 21:37\newcommand{\nocontentsline}[3]{}, then\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}and finally\newcommand{\hnumsubpara}{\tocless\numsubpara}and replace yournumsubparawithhnumsubpara. This will make the change on all your document and you're still able to have it in the ToC by usingnumsubparadirectly. Hope this answers your question. – Ivan May 22 '20 at 22:29\usepackage[stable]{footmisc}to your preamble. – Ivan May 23 '20 at 10:07\hnumsubparaat the end of the page :'( – Guliup May 23 '20 at 11:35