[Tex/LaTex] Renew command \makelettertitle in moderncv

frenchmoderncv

I want to modify the command \makelettertitle of the package moderncv so that I can have a heading in French style, that is, my data on the left, then below in 2 colums a "formule de politesse" on the left and the company data on the right. Below this on the left the date, then on the right the "objet" (why I'm sending the letter) and below the \opening.

elements

The thing is that if I try to to a renewcommand it gives me many extrange errors 😛

Thanks in advance

Best Answer

Simple way is to take the definitions from moderncvstyleclassic.sty and modify, and then put it inside makeatletter and \makeatother in your main file itself. (I don't advice modifying moderncvstyleclassic.sty)

Here is the modified content:

\makeatletter
%-------------------------------------------------------------------------------
%                letter style definition
%-------------------------------------------------------------------------------
% commands
\renewcommand*{\recomputeletterlengths}{%
  \recomputecvlengths%
  \setlength{\parskip}{6\p@}}

\newcommand*{\subject}[1]{\def\@subject{#1}}                    %% new command added

\renewcommand*{\makelettertitle}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputeletterlengths%
  % sender contact info
  %\hfill%                                      %%% <========== This commented
  \begin{minipage}{.5\textwidth}%
    \raggedright%                               %%% \reggedleft changed to raggedright                    
    \addressfont\textcolor{color2}{%            %%% change color here if you want it black or...
      {\bfseries\upshape\@firstname~\@familyname}\@firstdetailselementfalse%
      \ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
        \ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}}%
      \ifthenelse{\isundefined{\@mobile}}{}{\makenewline\mobilesymbol\@mobile}%
      \ifthenelse{\isundefined{\@phone}}{}{\makenewline\phonesymbol\@phone}%
      \ifthenelse{\isundefined{\@fax}}{}{\makenewline\faxsymbol\@fax}%
      \ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
      \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
      \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}}%
    \end{minipage}\\[2em]
  % recipient block
  Attention: \quad \begin{minipage}[t]{.5\textwidth}                  %%%  Changed here 
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress\\[2em]%
    \@date\\[1.5em]%                                                  %%% Changed here
  \end{minipage}
  % date
  \hfill% US style
%  \\[1em]% UK style
  \null\\[2em]%                                                         %%% Changed here    
  \raggedright%
  \ifthenelse{\isundefined{\@subject}}{}{%                              %% new command added
    \begin{tabular}{ p{0.08\textwidth} p{0.92\textwidth} }
    Objet: & \raggedright \@subject
    \end{tabular}
    \\[1.5em]}%
  % opening
  \raggedright%
  \@opening\\[1.5em]%
  \hspace{0pt}\par\vspace{-\baselineskip}\vspace{-\parskip}}

\renewcommand*{\makeletterclosing}{
  \@closing\\[3em]%
  {\bfseries \@firstname~\@familyname}%
  \ifthenelse{\isundefined{\@enclosure}}{}{%
    \\%
    \vfill%
    {\color{color2}\itshape\enclname: \@enclosure}}}
\makeatother

Change whatever you want like color of the address etc in this.

The full code will be

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}

\usepackage[scale=0.75]{geometry}

\makeatletter
%-------------------------------------------------------------------------------
%                letter style definition
%-------------------------------------------------------------------------------
% commands
\renewcommand*{\recomputeletterlengths}{%
  \recomputecvlengths%
  \setlength{\parskip}{6\p@}}

\newcommand*{\subject}[1]{\def\@subject{#1}}                    %% new command added

\renewcommand*{\makelettertitle}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputeletterlengths%
  % sender contact info
  %\hfill%                                      %%% <========== This commented
  \begin{minipage}{.5\textwidth}%
    \raggedright%                               %%% \reggedleft changed to raggedright                    
    \addressfont\textcolor{color2}{%            %%% change color here if you want it black or...
      {\bfseries\upshape\@firstname~\@familyname}\@firstdetailselementfalse%
      \ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
        \ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}}%
      \ifthenelse{\isundefined{\@mobile}}{}{\makenewline\mobilesymbol\@mobile}%
      \ifthenelse{\isundefined{\@phone}}{}{\makenewline\phonesymbol\@phone}%
      \ifthenelse{\isundefined{\@fax}}{}{\makenewline\faxsymbol\@fax}%
      \ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
      \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
      \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}}%
    \end{minipage}\\[2em]
  % recipient block
  Attention: \quad \begin{minipage}[t]{.5\textwidth}                  %%%  Changed here 
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress\\[2em]%
    \@date\\[1.5em]%                                                  %%% Changed here
  \end{minipage}
  % date
  \hfill% US style
%  \\[1em]% UK style
  \null\\[2em]%                                                         %%% Changed here    
  \raggedright%
  \ifthenelse{\isundefined{\@subject}}{}{%                              %% new command added
    \begin{tabular}{ p{0.08\textwidth} p{0.92\textwidth} }
    Objet: & \raggedright \@subject
    \end{tabular}
    \\[1.5em]}%
  % opening
  \raggedright%
  \@opening\\[1.5em]%
  \hspace{0pt}\par\vspace{-\baselineskip}\vspace{-\parskip}}

\renewcommand*{\makeletterclosing}{
  \@closing\\[3em]%
  {\bfseries \@firstname~\@familyname}%
  \ifthenelse{\isundefined{\@enclosure}}{}{%
    \\%
    \vfill%
    {\color{color2}\itshape\enclname: \@enclosure}}}
\makeatother

% personal data
\firstname{John}
\familyname{Doe}
\title{Resumé title}                          % optional, remove / comment the line if not wanted
\address{street and number}{postcode city}    % optional, remove / comment the line if not wanted
\mobile{+1~(234)~567~890}                     % optional, remove / comment the line if not wanted
\phone{+2~(345)~678~901}                      % optional, remove / comment the line if not wanted
\fax{+3~(456)~789~012}                        % optional, remove / comment the line if not wanted
\email{john@doe.org}                          % optional, remove / comment the line if not wanted
\homepage{www.johndoe.com}                    % optional, remove / comment the line if not wanted
\extrainfo{additional information}            % optional, remove / comment the line if not wanted
\photo[64pt][0.4pt]{picture}                  % optional, remove / comment the line if not wanted; 
\quote{`` A witty and playful quote''}        % optional, remove / comment the line if not wanted


%----------------------------------------------------------------------------------
\begin{document}

%-----       letter       ---------------------------------------------------------
% recipient data
\recipient{Company Recruitment team}{Company, Inc.\\123 somestreet\\some city}
\date{January 01, 1984}
\subject{This is to fill some text that goes in to two lines and many more here we come to the second line and it is neat}     %% use subject here
\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 \]

\makeletterclosing

\end{document}

enter image description here