4

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.

  • 1
    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
  • 1
    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
  • 1
    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
3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.