# Add the field “Subject” to moderncv letter

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
\par%
% recipient block
\begin{minipage}[t]{.5\textwidth}
\raggedright%
{\bfseries\upshape\@recipientname}\\%
\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.

• it would be better to provide a usable example, but also what is your question? The code looks more like an answer than a question. (although you should not have \noindent after the \bigskip) – David Carlisle Sep 5 '16 at 9:19
• @DavidCarlisle yes but not a correct answer i got some errors (not related to the fact \@subject is not defined yet) when copy pasting this code to override makeletterhead definition. You can't use \spacefactor' in internal vertical mode. There's no line here to end.... – Cfun Sep 5 '16 at 9:21
• but that's just the standard "use \makeatletter or put the code in a package" that applies to any command with @ in its name, unrelated to moderncv. you just want \newcommand\subject[1]{\def\@subject{#1}} to be defined somewhere that @ is a letter or don't use @ use \Xsubject or any other internal name that is a valid command name. – David Carlisle Sep 5 '16 at 9:26
• but anyway if you are asking about an error message the example code should be a complete document that generates the error. – David Carlisle Sep 5 '16 at 9:28
• @DavidCarlisle thanks another silly mistake from me, indeed it was because the lack of\makeatletter and \makeatother:) \newcommand\subject[1]{\def\@subject{#1}} was helpful as well you can post an answer or i will. – Cfun Sep 5 '16 at 9:34

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}
\phone[mobile]{00~00~00~00~00}

%%%%
\makeatletter
\newcommand\subject[1]{\def\@subject{#1}}

\par%

\begin{minipage}[t]{.5\textwidth}
\raggedright%
{\bfseries\upshape\@recipientname}\\%
\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}\\
\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}
\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.