I am modifying my cover letter with moderncv
. In particular, I want to add a title line, justifying the body text and align both adresses on the same height (companies adress top left, my adress top right). I found a couple of posts to the regarding Topics and I add the code parts into my TeX file. They are all working singular, but not in combination and I can't figure out why. Here is the MWE:
\documentclass[12pt,a4paper,sans]{moderncv}
\usepackage[ngerman]{babel}
\usepackage{tabularx}
% moderncv themes
\moderncvstyle{classic}
\moderncvcolor{blue}
\setlength{\hintscolumnwidth}{3.3cm}
% character encoding
\usepackage[utf8]{inputenc}
\name{Name}{name}
\title{Lebenslauf}
\address{...}{...}
\phone[mobile]{...}
\email{Mail}
%Justification
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\makeletterhead}% <cmd>
{\raggedright \@opening}% <search>
{\@opening}% <replace>
{}{}% <success><failure>
\makeatother
%Adds title
\makeatletter
\patchcmd{\makeletterhead}{%search
\raggedright%
\@opening\\[1.5em]%
}{%replace
\raggedright%
\textbf{\@title}\\[1.5em]
\@opening\\[1.5em]%
}{%success
}{%failure
}
\makeatother
%Should align both adresses on the same "height"
\makeatletter
\renewcommand*{\makeletterhead}{%
% recompute lengths (in case we are switching from letter to resume, or vice versa)
\recomputeletterlengths%
% recipient block
\begin{minipage}[t]{.49\textwidth} % <================================
\raggedright%
\addressfont%
{\bfseries\upshape\@recipientname}\\%
\@recipientaddress%
\end{minipage}
% sender contact info
\hfill%
\begin{minipage}[t]{.49\textwidth}% <=================================
% optional detailed information
\if@details%
\raggedleft%
\addressfont\textcolor{color2}{%
{\bfseries\upshape\@firstname~\@lastname}\@firstdetailselementfalse%
% optional detailed information
\ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
\ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}% if \addresstreet is defined, \addresscity and addresscountry will always be defined but could be empty
\ifthenelse{\equal{\@addresscountry}{}}{}{\makenewline\@addresscountry}}%
\collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
\makenewline\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}%
\ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
\ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
\ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}}\fi%
\\[1em] % <=======================================================
\@date % <========================================================
\end{minipage}\\[2em]
% opening
% \raggedright% <=======================================================
\@opening\\[1.5em]%
% ensure no extra spacing after \makelettertitle due to a possible blank line
% \ignorespacesafterend% not working
\hspace{0pt}\par\vspace{-\baselineskip}\vspace{-\parskip}}
\makeatother
\begin{document}
\makecvtitle
\section{Foo}
\section{Foo2}
\subsection*{FooFoo}
\clearpage
%----- letter ---------------------------------------------------------
% recipient data
\recipient{Company Recruitment team}{Company, Inc.\\123 somestreet\\some city}
\title{Heading should look like this} % <===============================
\date{January 01, 1984}
\opening{Dear Sir or Madam,}
\closing{Yours faithfully,}
\enclosure[Attached]{curriculum vit\ae{}}
\makelettertitle
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ullamcorper
neque sit amet lectus facilisis sed luctus nisl iaculis. Vivamus at neque
arcu, sed tempor quam. Curabitur pharetra tincidunt tincidunt. Morbi
volutpat feugiat mauris, quis tempor neque vehicula volutpat. Duis
tristique justo vel massa fermentum accumsan. Mauris ante elit, feugiat
vestibulum tempor eget, eleifend ac ipsum. Donec scelerisque lobortis
ipsum eu vestibulum. Pellentesque vel massa at felis accumsan rhoncus.
Suspendisse commodo, massa eu congue tincidunt, elit mauris pellentesque
orci, cursus tempor odio nisl euismod augue. Aliquam adipiscing nibh ut
odio sodales et pulvinar tortor laoreet. Mauris a accumsan ligula.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
inceptos himenaeos. Suspendisse vulputate sem vehicula ipsum varius nec
tempus dui dapibus. Phasellus et est urna, ut auctor erat. Sed tincidunt
odio id odio aliquam mattis. Donec sapien nulla, feugiat eget adipiscing
sit amet, lacinia ut dolor. Phasellus tincidunt, leo a fringilla
consectetur, felis diam aliquam urna, vitae aliquet lectus orci nec
velit. Vivamus dapibus varius blandit.
Duis sit amet magna ante, at sodales diam. Aenean consectetur porta risus
et sagittis. Ut interdum, enim varius pellentesque tincidunt, magna
libero sodales tortor, ut fermentum nunc metus a ante. Vivamus odio leo,
tincidunt eu luctus ut, sollicitudin sit amet metus. Nunc sed orci
lectus. Ut sodales magna sed velit volutpat sit amet pulvinar diam
venenatis.
Albert Einstein discovered that $e=mc^2$ in 1905.
\[ e=\lim_{n \to \infty} \left(1+\frac{1}{n}\right)^n \]
\end{document}
The cover letter is justified and the adresses are on the same height, but the title is not involved. Maybe someone knows how to solve that problem. I am not so advanced to understand the changes in the \patchcmd
arguments, Maybe there is the problem.
I already tried the regarding code here, but it doesnt work in combination with the justificatoin and the alignment of the adress
moderncv
because your attached CV? If you don't have a CV attached to it, you can just recreate a cover letter using the regulararticle
document class.