From d88a8cf436d8aaa716fb9a6ebd7f42a791bcfaa9 Mon Sep 17 00:00:00 2001 From: LLdaniel Date: Mon, 25 Mar 2024 23:17:46 +0100 Subject: [PATCH] fix issue #69: compensating wrong (sub)section spacing with negative vspace --- moderncvbodyv.sty | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/moderncvbodyv.sty b/moderncvbodyv.sty index 96be31e..ec2c5c3 100644 --- a/moderncvbodyv.sty +++ b/moderncvbodyv.sty @@ -44,6 +44,8 @@ \@initializelength{\separatorcolumnwidth} \setlength{\separatorcolumnwidth}{0.025\textwidth} \@initializelength{\separatorrulewidth} \setlength{\separatorrulewidth}{1.2\p@}% \@initializelength{\maincolumnwidth} +\@initializelength{\multilinecompensationlength} +\@initializelength{\thissectionwidth} % used by \cvdoubleitem \@initializelength{\doubleitemcolumnwidth} % used by \cvlistitem @@ -54,6 +56,9 @@ \@initializelength{\listdoubleitemcolumnwidth} %\@initializelength{\listdoubleitemmaincolumnwidth} +% numbers +% used by \calculatecompensation +\@initializecommand{\numoflines}{0} % commands \@initializecommand{\recomputecvbodylengths}{% % body lengths @@ -67,12 +72,21 @@ % regular lengths \setlength{\parskip}{0\p@}} +\newcommand{\calculatecompensation}[1]{% + % calculate the number of lines used by sections and subsections + \settowidth{\thissectionwidth}{#1}% + \renewcommand{\numoflines}{\numexpr\thissectionwidth/\hintscolumnwidth\relax}% + \setlength{\multilinecompensationlength}{\dimexpr\hintscolumnwidth*\numoflines\relax}% + } + \@initializeif{\if@aftersection}\@aftersectionfalse% \RenewDocumentCommand{\section}{sm}{% \addvspace{2.5ex}% \phantomsection{}% reset the anchor for hyperrefs \addcontentsline{toc}{section}{#2}% - \noindent\rlap{\@cvitem{\raggedleft\sectionstyle{#2}}{}}% + \calculatecompensation{\sectionstyle{#2}}% calculate the vspace compensation for current section + \noindent\rlap{\@cvitem{\raggedleft\sectionstyle{#2}\ifthenelse{\multilinecompensationlength<2}{}{\vspace{-\multilinecompensationlength}}}{}}% + %\noindent\rlap{\@cvitem{\raggedleft\sectionstyle{#2}}{}}% \nobreak\@afterheading\@aftersectiontrue\ignorespaces} %\@initializeif{\if@aftersubsection}\@aftersubsectionfalse% @@ -83,7 +97,8 @@ \par\ignorespaces\fi% \phantomsection{}% reset the anchor for hyperrefs \addcontentsline{toc}{subsection}{#2}% - \noindent\rlap{\@cvitem{\if@aftersection\else\@moderncvstrut{4pt}{24pt}\fi\raggedleft\subsectionstyle{#2}}{}}% + \calculatecompensation{\subsectionstyle{#2}}% calculate the vspace compensation for current section + \noindent\rlap{\@cvitem{\if@aftersection\else\@moderncvstrut{4pt}{24pt}\fi\raggedleft\subsectionstyle{#2}\ifthenelse{\multilinecompensationlength<2}{}{\vspace{-\multilinecompensationlength}}}{}}% \nobreak\@afterheading\@aftersectiontrue\ignorespaces} \renewcommand*{\cvitem}[3][.5ex]{%