mirror of
https://github.com/moderncv/moderncv.git
synced 2026-10-20 08:17:03 +02:00
Fix orphaned \section and \subsection headings (#226)
In the body variants that typeset headings with \cvitem (i/ii, used by the
casual and classic styles, and vi, used by the contemporary style), \cvitem
ends with \par\addvspace{0ex}. That contributes glue right after the heading
box and *before* the \nobreak of the heading definition. Glue following a box
is a legal page breakpoint, so LaTeX was free to break there and leave the
heading alone at the bottom of a page while its first \cventry moved to the
next page.
Add \@cvheadingitem to moderncv.cls, which calls \cvitem with \addvspace
gobbled, and use it in the affected heading definitions. The \nobreak is then
the first item after the heading box, so the page can only break before the
heading. The heading's own \par\nobreak\addvspace{...} still supplies the
space below it, so output is unchanged whenever no break occurs.
Verified with pdflatex on all six shipped styles: renderings are
pixel-identical to the previous ones for documents without an orphan, and
casual/classic (\section and \subsection) plus contemporary (\subsection) no
longer orphan headings. banking, oldstyle and fancy were never affected, as
their headings do not go through \cvitem.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
c2374bcad4
commit
a31e3af59e
4 changed files with 17 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
10
moderncv.cls
10
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]{}
|
||||
|
|
|
|||
|
|
@ -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]{%
|
||||
|
|
|
|||
|
|
@ -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]{%
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue