LaTeX Commands to Prevent Orphaned cventry Titles in ModernCV Templates
\needspace{5\baselineskip} and \enlargethispage{2-3\baselineskip} are the specific LaTeX commands used to keep CV entries intact by forcing page breaks before titles that would otherwise dangle alone at the bottom of a page.
Orphaned section titles in LaTeX CVs create broken layouts and confuse ATS parsers. The ai-job-search repository by MadsLorentzen solves this for ModernCV banking templates by implementing specific LaTeX commands to prevent orphaned cventry titles that keep job entries intact across page boundaries.
The Orphaned Title Problem in ModernCV
In the ModernCV banking template, the \cventry command formats each job or education entry. When a title appears at the bottom of a page while its bullet list spills onto the next, the visual hierarchy breaks and automated parsers may lose context. This fragmentation degrades both professional appearance and machine readability.
Required LaTeX Packages
The solution requires the needspace package, which provides commands for conditional page breaking. Load it once in your document preamble:
\usepackage{needspace}
The Two Commands That Fix Page Breaks
\needspace – Force Entry Integrity
Placed immediately before a \cventry, \needspace{5\baselineskip} checks the remaining vertical space on the current page. If less than five lines of text remain, LaTeX forces a page break before the entry, ensuring the title and at least the first few bullet points stay together on the following page.
\enlargethispage – Rescue Trailing Content
For entries that fit but push a final bullet onto the next page, \enlargethispage{2-3\baselineskip} temporarily expands the current page height by two to three lines. Added after the \cventry, this command prevents splitting a short trailing list without moving the entire entry.
Implementation in the ai-job-search Repository
According to the source code in MadsLorentzen/ai-job-search, these protections are automated across multiple files:
README.md(line 221) documents the PDF verification loop that applies these commands to fix orphaned titles during CV generation.CLAUDE.md(line 126) lists the explicit checklist item "No orphaned\cventrytitles" and specifies the exact commands to use..claude/skills/job-application-assistant/05-cv-templates.md(line 161) provides the step-by-step instruction to insert\needspace{5\baselineskip}before each\cventryand includes theneedspacepackage requirement..claude/commands/apply.md(line 213) shows the exact command snippet used by the/applyautomation to enforce orphan-prevention logic during job application processing.
Complete Working Example
\documentclass[11pt,a4paper,roman]{moderncv}
\moderncvstyle{banking}
\usepackage{needspace} % Required for page break control
\begin{document}
\needspace{5\baselineskip} % Prevent orphaned title
\cventry{2020--2023}{Senior Data Scientist}{Acme Corp}{Copenhagen, Denmark}{}{
\begin{itemize}
\item Developed a recommender system that increased click-through rate by 12\%
\item Led a team of 5 engineers and mentored junior staff
\item Designed an automated data-pipeline using Airflow and Docker
\end{itemize}
}
\enlargethispage{2\baselineskip} % Optional: squeeze in trailing content
\end{document}
Summary
- Load the
needspacepackage in your preamble to access orphan-prevention commands. - Insert
\needspace{5\baselineskip}immediately before each\cventryto keep entries intact. - Apply
\enlargethispage{2-3\baselineskip}after entries that narrowly overflow to avoid splitting bullet lists. - Reference the ai-job-search repository files including
README.md(line 221) andCLAUDE.md(line 126) for automated implementation patterns.
Frequently Asked Questions
Why use 5\baselineskip specifically for \needspace?
This reserves enough vertical space for the \cventry title plus approximately four lines of bullet content. If fewer than five lines remain on the page, LaTeX pushes the entire entry to the next page, preventing the title from dangling alone at the bottom.
Can I use \enlargethispage for every cventry entry?
No, reserve \enlargethispage for exceptional cases where an entry mostly fits but one or two bullet lines overflow. Overusing page enlargement creates inconsistent bottom margins and violates standard typography practices.
Does this solution work with all ModernCV styles?
The commands function across all ModernCV styles, but the repository specifically targets the banking template where \cventry formatting is most susceptible to orphan issues due to its compact, horizontal layout structure.
How do these commands improve ATS parsing?
Keeping \cventry titles physically adjacent to their content prevents PDF text extraction algorithms from inserting artificial page breaks between a job title and its responsibilities, ensuring parsing systems correctly associate dates and employers with the appropriate bullet points.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →