[Tex/LaTex] Merging scrlttr2 and komacv layout

scrlttr2

I want to merge a scrlttr2 and a komacv.

I want the headers from komacv to be congruent with those of scrlttr2. So on page 1 of komacv there should be the blue line (with same length as in scrlttr2 page 1) and the name and address stuff.

Page 2 of the komacv should accordingly have the header of page 2 of scrlttr2 (with the corresponding length on page 2).

The photo from komacv needs to stay on the left side. It should align with the left side of the blue boxes (or with the left end of the header).

I need your help! Thanks!

Update: Deleted source code and graphics, because they are not necessary anymore.

Best Answer

komacv is based on the KOMA-Script class scrartcl. So it is possible to use the relatively new KOMA-Script package scrletter to set the letter and the cv in one document.

Additional I would use scrlayer to define a new page style for the first pages of both the letter and the cv.

But komacv still loads scrpage2 and this package can not be used together with scrlayer-scrpage. So first of all

\RequirePackage{scrlfile}
\PreventPackageFromLoading[\usepackage{scrlayer-scrpage}]{scrpage2}

ensures that komacv does not load scrpage2.

Then we can the define a new layer using the letter pseudolength

\DeclareNewLayer[
  background,
  area={\useplength{toaddrhpos}}{\useplength{firstheadvpos}}%
       {\dimexpr\paperwidth-2\useplength{toaddrhpos}\relax}{3cm},
  contents={\parbox[t]{\layerwidth}{\raggedleft
    \usekomavar{fromname}\strut\\[-6pt]
    \textcolor{myblue}{\rule{\linewidth}{2pt}}\\
    \usekomavar{fromaddress}}}
]{firsthead}

and declare a new page style using this layer

\DeclarePageStyleByLayers{firstpage}{firsthead}

To align the photo you can insert this directly or redefine maketitle

\renewcommand\maketitle{%
  %\hspace*{\dimexpr-.5\paperwidth+.5\textwidth+\useplength{toaddrhpos}\relax}% to align with the headsepline
  \fcolorbox{mycolor}{white}{\includegraphics[width=3cm]{jeyre}}%
}

enter image description here

enter image description here

or alternatively

enter image description here

Code:

\RequirePackage{scrlfile}
\PreventPackageFromLoading[\usepackage{scrlayer-scrpage}]{scrpage2}

\documentclass[style=classic]{komacv}
\hypersetup{hypertexnames=false}

\usepackage{scrletter}
\setkomavar{fromname}{Jane Eyre}
\setkomavar{fromaddress}{Ferndean House\\Ferndean Village}
\setkomavar{subject}{Writing a letter}
\setkomavar{firsthead}{}

\KOMAoptions{headsepline=2pt,plainheadsepline,draft=false}
\setkomafont{headsepline}{\color{mycolor}}
\renewcommand\pagemark{\usekomafont{pagenumber}Page~\thepage}
\clearpairofpagestyles
\ohead[\pagemark]{}

\DeclareNewLayer[
  background,
  area={\useplength{toaddrhpos}}{\useplength{firstheadvpos}}%
       {\dimexpr\paperwidth-2\useplength{toaddrhpos}\relax}{3cm},
  contents={\parbox[t]{\layerwidth}{\raggedleft
    \usekomavar{fromname}\strut\\[-6pt]
    \textcolor{myblue}{\rule{\linewidth}{2pt}}\\
    \usekomavar{fromaddress}}}
]{firsthead}
\DeclarePageStyleByLayers{firstpage}{firsthead}

\renewcommand\maketitle{%
  \hspace*{\dimexpr-.5\paperwidth+.5\textwidth+\useplength{toaddrhpos}\relax}%
  \fcolorbox{mycolor}{white}{\includegraphics[width=3cm]{jeyre}}%
}

\usepackage{lmodern}
\begin{document}
\begin{letter}{%
        Ernst Hemingway\\
        Main street\\
        2300 PAMPLONA%
}
\opening{}
\thispagestyle{firstpage}
\pagestyle{plain.scrheadings}

Bulls are nice, but the last general meeting was about one year ago.
I want to remind you, that the constitution of our
club advises you to make a general meeting every
six month. Because of this I expect the executive
board to detain such a meeting immediately.

\pagebreak

I want to remind you, that the constitution of our
club advises you to make a general meeting every
six month. Because of this I expect the executive
board to detain such a meeting immediately.
\closing{Thank you}
\end{letter}
%----------------------------------------------------------
\cleardoublepage
\thispagestyle{firstpage}
\pagestyle{plain.scrheadings}
\raggedbottom
\pagenumbering{arabic}
\maketitle

\section{Personal Information}
\cvitem{Date of birth}{February 15, 1828}
\cvitem{Nationality}{British}
\cvitem{Civil Status}{Married, two children}
...
\clearpage
\section{All Elements}
\subsection{cvitem}
\cvitem{header}{cvitem text
  \begin{compactenum}
    \item compactenum item one
    \item compactenum item two
  \end{compactenum}
}
\end{document}

Update (because of a comment)

If the bars in cv should be 4pt height you have to redefine \@cvbarsection to

\makeatletter
\renewcommand\@cvbarsection[1]{%
  \origsection*{
    \phantomsection{}
    \addcontentsline{toc}{section}{#1}%
    \cvitem[0pt]{%
      \raggedleft\hintstyle{\color{@secbarcolor}%
        \rule{\@hintscolwidth}{4pt}}% <- defines the bar
    }{\sectionstyle{#1}}
  }
}
\makeatother

But note this is only a small change of the original komacv code. The original komacv code already breaks some of the possibilities of the current KOMA-Script version.

Result with roboto font:

enter image description here

Code:

\RequirePackage{scrlfile}
\PreventPackageFromLoading[\usepackage{scrlayer-scrpage}]{scrpage2}

\documentclass[style=classic]{komacv}
\hypersetup{hypertexnames=false}

\usepackage{scrletter}
\setkomavar{fromname}{Jane Eyre}
\setkomavar{fromaddress}{Ferndean House\\Ferndean Village}
\setkomavar{subject}{Writing a letter}
\setkomavar{firsthead}{}

\KOMAoptions{headsepline=2pt,plainheadsepline,draft=false}
\setkomafont{headsepline}{\color{mycolor}}
\renewcommand\pagemark{\usekomafont{pagenumber}Page~\thepage}
\clearpairofpagestyles
\ohead[\pagemark]{}

\DeclareNewLayer[
  background,
  area={\useplength{toaddrhpos}}{\useplength{firstheadvpos}}%
       {\dimexpr\paperwidth-2\useplength{toaddrhpos}\relax}{3cm},
  contents={\parbox[t]{\layerwidth}{\raggedleft
    \usekomavar{fromname}\strut\\[-6pt]
    \textcolor{myblue}{\rule{\linewidth}{2pt}}\\
    \usekomavar{fromaddress}}}
]{firsthead}
\DeclarePageStyleByLayers{firstpage}{firsthead}

\renewcommand\maketitle{%
  \hspace*{\dimexpr-.5\paperwidth+.5\textwidth+\useplength{toaddrhpos}\relax}%
  \fcolorbox{mycolor}{white}{\includegraphics[width=3cm]{jeyre}}%
}
\usepackage{roboto}
\makeatletter
\renewcommand\@cvbarsection[1]{%
  \origsection*{
    \phantomsection{}
    \addcontentsline{toc}{section}{#1}%
    \cvitem[0pt]{%
      \raggedleft\hintstyle{\color{@secbarcolor}%
        \rule{\@hintscolwidth}{4pt}}%
    }{\sectionstyle{#1}}
  }
}
\makeatother

\begin{document}
\begin{letter}{%
        Ernst Hemingway\\
        Main street\\
        2300 PAMPLONA%
}
\opening{}
\thispagestyle{firstpage}
\pagestyle{plain.scrheadings}

Bulls are nice, but the last general meeting was about one year ago.
I want to remind you, that the constitution of our
club advises you to make a general meeting every
six month. Because of this I expect the executive
board to detain such a meeting immediately.

\pagebreak

I want to remind you, that the constitution of our
club advises you to make a general meeting every
six month. Because of this I expect the executive
board to detain such a meeting immediately.
\closing{Thank you}
\end{letter}
%----------------------------------------------------------
\cleardoublepage
\thispagestyle{firstpage}
\pagestyle{plain.scrheadings}
\raggedbottom
\pagenumbering{arabic}
\maketitle

\section{Personal Information}
\cvitem{Date of birth}{February 15, 1828}
\cvitem{Nationality}{British}
\cvitem{Civil Status}{Married, two children}
...
\clearpage
\section{All Elements}
\subsection{cvitem}
\cvitem{header}{cvitem text
  \begin{compactenum}
    \item compactenum item one
    \item compactenum item two
  \end{compactenum}
}
\end{document}

Use the opitional argument of \rule if you want to change the vertical position of the bars.


Second update

komacv does some hacks witch break some of the possibilities of the current KOMA versions. Especially \RecdeclareSectionCommand does not work. Also the commands \beforesecvspace etc. seems to have no effect. There is a information in the komacv documentation:

Note that the section and subsection definition of komacv needs improvement, so the setting of these lengths may not produce the desired result and the result may change in future versions.

As a workaround you can insert \vspace*{...} in the redefinition of \@cvbarsection and \@cvbarsubsection but note this are only hacks:

\usepackage{roboto}
\makeatletter
\renewcommand\@cvbarsection[1]{%
  \vspace*{-1\baselineskip}% <- 
  \origsection*{
    \phantomsection{}
    \addcontentsline{toc}{section}{#1}%
    \cvitem[0pt]{%
      \raggedleft\hintstyle{\color{@secbarcolor}%
        \rule{\@hintscolwidth}{4pt}}%
    }{\sectionstyle{#1}}
  }
}
\renewcommand\@cvbarsubsection[1]{%
  \vspace*{-.5\baselineskip}% <- 
  \origsubsection*{
    \cvitem[0pt]{}{\subsectionstyle{#1}}
  }%
}
\makeatother