diff --git a/CHANGELOG b/CHANGELOG index 50ddd43..d1c6737 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,10 @@ version next - Fix "Underfull \hbox (badness 10000)" warning in banking \subsection dotted rules by adding \hss glue as in \dotfill (#307) - Update "circle" option to allow for half-filled circles in skill matrix (#309) +- Fix orphaned \section and \subsection headings in the casual, classic and + contemporary styles: the trailing \addvspace of the \cvitem used to typeset + the heading allowed a page break between the heading and its first entry + (#226) version 2.6.1 (24 Jun 2026) - Allow the customisation of the contemporary style (#297) diff --git a/moderncv.cls b/moderncv.cls index 1bc93cf..7cfaafd 100644 --- a/moderncv.cls +++ b/moderncv.cls @@ -567,6 +567,16 @@ % usage: \cvitem[spacing]{header}{text} \newcommand*{\cvitem}[3][.25em]{} +% typesets a (sub)section heading as a \cvitem, without the trailing vertical +% space \cvitem normally adds +% usage: \@cvheadingitem{header}{text} +% the trailing \addvspace of \cvitem would contribute glue right after the +% heading box and before the \nobreak of the heading definition; glue after a +% box is a legal page breakpoint, so LaTeX could leave the heading orphaned at +% the bottom of a page. Gobbling it makes \nobreak the first item following +% the heading box, so the page can only break before the heading +\newcommand*{\@cvheadingitem}[2]{{\let\addvspace\@gobble\cvitem[0ex]{#1}{#2}}} + % makes a resume line 2 headers and their corresponding text % usage: \cvdoubleitem[spacing]{header1}{text1}{header2}{text2} \newcommand*{\cvdoubleitem}[5][.25em]{} diff --git a/moderncvbodyi.sty b/moderncvbodyi.sty index b1155d2..3de93c6 100644 --- a/moderncvbodyi.sty +++ b/moderncvbodyi.sty @@ -78,14 +78,14 @@ \par\addvspace{2.5ex}% \phantomsection{}% reset the anchor for hyperrefs \addcontentsline{toc}{section}{#2}% - \cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{bodyrulecolor}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}% + \@cvheadingitem{\strut\raggedleft\raisebox{\baseletterheight}{\color{bodyrulecolor}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}% \par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading \RenewDocumentCommand{\subsection}{sm}{% \par\addvspace{1ex}% \phantomsection{}% reset the anchor for hyperrefs \addcontentsline{toc}{subsection}{#2}% - \cvitem[0ex]{}{\strut\subsectionstyle{#2}}% + \@cvheadingitem{}{\strut\subsectionstyle{#2}}% \par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading \renewcommand*{\cvitem}[3][.25em]{% diff --git a/moderncvbodyvi.sty b/moderncvbodyvi.sty index 79b9d3f..58ab97a 100644 --- a/moderncvbodyvi.sty +++ b/moderncvbodyvi.sty @@ -92,7 +92,7 @@ \par\addvspace{1ex}% \phantomsection{}% reset the anchor for hyperrefs \addcontentsline{toc}{subsection}{#2}% - \cvitem[0ex]{}{\strut\subsectionstyle{#2}}% + \@cvheadingitem{}{\strut\subsectionstyle{#2}}% \par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading \renewcommand*{\cvitem}[3][.25em]{%