[Tex/LaTex] Add the field “Subject” to moderncv letter

letterheadmacrosmoderncv

As discussed on this forum latex-community: How to include Subject to letter, I'd like to add an extra field "Subject: " to moderncv letter template.

\bigskip
\textbf{Subject: \@subject}
\bigskip\noindent

the new \makeletterhead command will be something like this:

\renewcommand*{\makeletterhead}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputeletterlengths%
  % sender block
  \makehead%
  \par%
   % recipient block
  \begin{minipage}[t]{.5\textwidth}
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress%
  \end{minipage}
  % date
  \hfill% US style
%  \\[1em]% UK style
  \@date\\[2em]% US informal style: "January 1, 1900"; UK formal style: "01/01/1900"
%_______________________
\bigskip
\textbf{Subject: \@subject}
\bigskip\noindent
%_______________________
  % 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}}

Not to forget that the parameter \@subject should be retrieved somewhere.

EDIT

The question is how to add a "Subject" field in a way that when the command \makelettertitle is executed the subject text will be placed before the openning statement.

Best Answer

Thanks to David Carlisle's comment I have corrected my attempt, here's an example:

\documentclass[10pt,a4paper,sans]{moderncv}
\moderncvstyle{banking}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.85]{geometry}

\nopagenumbers{}
\renewcommand*{\namefont}{\fontsize{20}{29}\mdseries\upshape}

\firstname{LaTeX}
\familyname{MiKTeX}
\address{Tex.Stackexchange.com}{0000}
\phone[mobile]{00~00~00~00~00}
\email{project-admin@latex-project.org}

%%%%
%Add the field "Subject" to the definition of the letter header
\makeatletter
\newcommand\subject[1]{\def\@subject{#1}}

\renewcommand*{\makeletterhead}{%
  \makehead%
  \par%

  \begin{minipage}[t]{.5\textwidth}
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress%
  \end{minipage}
  % date
  \hfill% US style
%  \\[1em]% UK style
  \@date\\[2em]% US informal style: "January 1, 1900"; UK formal style: "01/01/1900"
  %________ADDED_<<<<<<
\bigskip
\textbf{Subject: \@subject}\\
\noindent
%_______________________
  % opening
  \raggedright%
  \@opening\\[1.5em]%
  % ensure no extra spacing after \makelettertitle due to a possible blank line
  \hspace{0pt}\par\vspace{-\baselineskip}\vspace{-\parskip}}
\makeatother
%%%

\begin{document}
\recipient{Company Recruitment team}{Company, Inc.\\123 somestreet\\Some City 00000}
\date{Septembre 05, 2016}
\opening{Dear Sir or Madam,}
\closing{Yours faithfully,}
\enclosure[Attached]{curriculum vit\ae{}}
\subject{Apply for...}

\makelettertitle

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.

\makeletterclosing

\end{document}

The definition of the command \makeletterhead was picked from moderncvbodyiii.sty since the banking style (used in the example) uses moderncvbodyiii.sty file.