0

Following this already answered thread, I have a related but different question for you.

Problem :

I frequently get page breaks right after my counter because of the presence of footnotes in it : enter image description here

I know it is not recommended to use footnotes inside titles. However, I don't have the choice here. I also know that 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 for two reasons : - First, I have used them all and even created extra ones thanks to this community - Second, the counter does not reset at all in the document.

Partial solution :

titlesec or needspace packages works well for titles without footnotes.

Would it be possible to stick the next paragraph to my counter with footnotes? The document I am creating being quite long, it has to be automatic, i.e. I cannot manually add \pagebreak before lonely \numsubpara commands.

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}

Thank you all in advance !

Guliup
  • 96

2 Answers2

1

There are lots of problems with your definition of tocless and \numsubpara. You are using titlesec, and surely that provides good facilities for defining new sectioning commands! If not that, then you should use the support built in to LaTeX by using \@startsection. There is too much wrong with your little definition to cover it all

  • wrapper \tocless ends the group, cancelling settings from numsubpara
  • the last setting is a likely-wrong font setting, unless the rest of the document should be in the size of the title (you should use grouping for local font changes).
  • the \space before \vspace will sometimes give an extra blank line below the title
  • ending the title with \\ also leads to a spurious blank line (and warning message) if a blank line appears in the input.
  • do you really want a paragraph indent?
  • there is nothing preventing a page break in the middle of a two-line title.
  • the \vspace{2.8mm} is a place to break the page, and that is the problem hitting you this time.

To make the least change possible to your definition, change \space\vspace{2.8mm} to \vspace*{2.8mm}. Or somewhat cleaner, change \space\vspace{2.8mm}\\ to \\*[2.8mm].

The problem doesn't really involve the footnote, except by changing how much rtoom there is on the page.

0

I'm not sure that it is possible due to the order in which LaTeX sets up the printing of footnotes --- as I understand it LaTeX sees a \footnote and immediately plans on printing it before processing anything afterwards.

I have modified your MWE to use \footnotemark and \footnotetext but this is essentially a manual process, but perhaps it will give you some ideas.

% numsubparaprob.tex  SE 546518

\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}

\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]}}
\hnumsubpara{My command\footnotemark} % PW used \footnotemark

Text \footnotetext{\lipsum[1]} % PW used \footnotetext
\lipsum[1]

\tableofcontents

\end{document}
Peter Wilson
  • 28,066
  • It does not solve the problem but it is an interesting idea! One option could be fake footnote numbers in title and invisible footnote number at the beginning of the next paragraph? Since title and paragraph are supposed to be linked it should work! – Guliup May 27 '20 at 21:18