[Tex/LaTex] Include signature picture in cover letter in moderncv

moderncv

I created a cover letter with the moderncv package. My code is:

\documentclass[11pt,a4paper]{moderncv}
\moderncvtheme[green]{classic}                  
\usepackage[utf8]{inputenc}                  
\usepackage{floatflt}
\usepackage{fancyhdr} 
\usepackage{geometry}
\geometry{a4paper,left=2cm,right=1cm, top=2cm, bottom=1.5cm,headheight=21pt} 
\usepackage{tikz} 
\usepackage{wrapfig}
\usepackage{lipsum} 
\usepackage{footmisc}
\usepackage{xparse}
\usepackage[firstyear=1996,lastyear=2013]{moderntimeline}

% New page style
\fancypagestyle{myfancy}{
\fancyhead[L]{\parbox[t]{.3333\textwidth}{\sffamily\footnotesize
 Teest\\Test}}
\fancyhead[C]{\parbox[t]{.3333\textwidth}{\fixedphonesymbol\sffamily\footnotesize  213123312}}
\fancyhead[R]{\parbox[t]{.3333\textwidth}{\emailsymbol\sffamily\footnotesize  test@test.com}}
}
\makeatletter
\let\ps@plain\ps@myfancy
\let\ps@empty\ps@myfancy
\makeatother
\pagestyle{myfancy}

% Redefinitions of \makecvtitle, opening and closing to
% have the desired formatting for first and family names
\makeatletter
\renewcommand*{\makecvtitle}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputecvlengths%
  % optional detailed information (pre-rendering)
  \def\phonesdetails{}%
  \collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
    \protected@edef\phonesdetails{\phonesdetails\protect\makenewline\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}}%
  \def\socialsdetails{}%
  \collectionloop{socials}{% the key holds the social type (=symbol command prefix), the item holds the link
    \protected@edef\socialsdetails{\socialsdetails\protect\makenewline\csname\collectionloopkey socialsymbol\endcsname\collectionloopitem}}%
  \newbox{\makecvtitledetailsbox}%
  \savebox{\makecvtitledetailsbox}{%
    \addressfont\color{color2}%
    \begin{tabular}[b]{@{}r@{}}%
      \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}}%
      \phonesdetails% needs to be pre-rendered as loops and tabulars seem to conflict
      \ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
      \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
      \socialsdetails% needs to be pre-rendered as loops and tabulars seem to conflict
      \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}%
    \end{tabular}
  }%
  % optional photo (pre-rendering)
  \newbox{\makecvtitlepicturebox}%
  \savebox{\makecvtitlepicturebox}{%
    \ifthenelse{\isundefined{\@photo}}%
    {}%
    {%
      \hspace*{\separatorcolumnwidth}%
      \color{color1}%
      \setlength{\fboxrule}{\@photoframewidth}%
      \ifdim\@photoframewidth=0pt%
        \setlength{\fboxsep}{0pt}\fi%
      \framebox{\includegraphics[width=\@photowidth]{\@photo}}}}%
  % name and title
  \newlength{\makecvtitledetailswidth}\settowidth{\makecvtitledetailswidth}{\usebox{\makecvtitledetailsbox}}%
  \newlength{\makecvtitlepicturewidth}\settowidth{\makecvtitlepicturewidth}{\usebox{\makecvtitlepicturebox}}%
  \ifthenelse{\lengthtest{\makecvtitlenamewidth=0pt}}% check for dummy value (equivalent to \ifdim\makecvtitlenamewidth=0pt)
    {\setlength{\makecvtitlenamewidth}{\textwidth-\makecvtitledetailswidth-\makecvtitlepicturewidth}}%
    {}%
  \begin{minipage}[b]{\makecvtitlenamewidth}%
    \namestyle{\@firstname}\par\smallskip\namestyle{\@lastname}%
    \ifthenelse{\equal{\@title}{}}{}{\\[1.25em]\titlestyle{\@title}}%
  \end{minipage}%
  \hfill%
  % optional detailed information (rendering)
  \llap{\usebox{\makecvtitledetailsbox}}% \llap is used to suppress the width of the box, allowing overlap if the value of makecvtitlenamewidth is forced
  % optional photo (rendering)
  \usebox{\makecvtitlepicturebox}\\[2.5em]%
  % optional quote
  \ifthenelse{\isundefined{\@quote}}%
    {}%
    {{\centering\begin{minipage}{\quotewidth}\centering\quotestyle{\@quote}\end{minipage}\\[2.5em]}}%
  \par}% to avoid weird spacing bug at the first section if no blank line is left after \makecvtitle
\renewcommand*{\makeletterclosing}{
  \@closing\\[3em]%
  {\bfseries\@firstname\\\@lastname}%
  \ifthenelse{\isundefined{\@enclosure}}{}{%
    \\%
    \vfill%
    {\color{color2}\itshape\enclname: \@enclosure}}}
\renewcommand*{\makelettertitle}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputeletterlengths%
  % sender contact info
  \hfill%
  \begin{minipage}{.5\textwidth}%
    \raggedleft%
    \addressfont\textcolor{color2}{%
      {\bfseries\upshape\@firstname\\\@lastname}\@firstdetailselementfalse%
      \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}}%
    \end{minipage}\\[1em]
  % 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"
  % 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

\makeatletter
\renewcommand*{\bibliographyitemlabel}{\@biblabel{\arabic{enumiv}}}
\makeatother


% for timeline

\makeatletter
\pgfmathsetmacro\tl@textstartabove{\tl@width-2pt}
\NewDocumentCommand\tldatelabelcventryn{O{center}O{color1}mmmmmmm}{%
\pgfmathsetmacro\tl@endyear{\tl@lastyear}%
\pgfmathsetmacro\tl@startfraction{(#3-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
\pgfmathsetmacro\tl@endfraction{(\tl@endyear-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
 \cventry{\tikz[baseline]{%
     \useasboundingbox (0,-1.5ex) rectangle (\hintscolumnwidth,1ex);
     \fill [\tl@runningcolor] (0,0)
        rectangle (\hintscolumnwidth,\tl@runningwidth);
     \fill [#2] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear,yshift=5pt,anchor=#1] {#4}
        node {$\bullet$};
   }
}
{#5}{#6}{#7}{#8}{#9}
}
\newcommand\tllabelcventryn[9][color1]{%
  \gdef\Argi{#1}%
  \gdef\Argii{#2}%
  \gdef\Argiii{#3}%
  \gdef\Argiv{#4}%
  \gdef\Argv{#5}%
  \gdef\Argvi{#6}%
  \gdef\Argvii{#7}%
  \gdef\Argviii{#8}%
  \gdef\Argix{#9}%
  \auxtllabelcventryn
}
\def\auxtllabelcventryn#1{%
  \gdef\Argx{#1}%
\pgfmathsetmacro\tl@endyear{ifthenelse(\Argiii==0,\tl@lastyear,\Argiii)}
\pgfmathsetmacro\tl@startfraction{(\Argii-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
\pgfmathsetmacro\tl@endfraction{(\tl@endyear-\tl@firstyear)/(\tl@lastyear-\tl@firstyear)}%
 \cventry{\tikz[baseline=0pt]{
     \fill [\tl@runningcolor] (0,0)
        rectangle (\hintscolumnwidth,\tl@runningwidth);
     \useasboundingbox (0,-1.5ex)
        rectangle (\hintscolumnwidth,1ex);
     \fill [\Argi] (0,0)
        ++(\tl@startfraction*\hintscolumnwidth,0pt)
        node [tl@startyear,anchor=north east] {\Argiv} node [tl@startyear,above] {\Argv}
        rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width-1pt);
     \pgfmathsetlength{\pgf@xa}{\Argiii} \ifdim\pgf@xa=0pt
        \shade [left color=\Argi] (\tl@startfraction*\hintscolumnwidth,0)
            rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width);
     \else
        \fill [\Argi] (\tl@startfraction*\hintscolumnwidth,0)
            rectangle (\tl@endfraction*\hintscolumnwidth,\tl@width);
     \fi
     }
}
{\Argvi}{\Argvii}{\Argviii}{\Argix}{\Argx}%
}
\makeatother
%
\tltextstart[north]{\scriptsize}
\tltextend[south]{\scriptsize}

\firstname{Ctest}
\familyname{test}
\title{Curriculum vit\ae{}}              
\address{}{}  
\photo[128pt]{picture}                        

\begin{document}

\recipient{Test}{Test\\Test} 
\date{\today} 
\opening{Dear Commitee Members:} 
\closing{Sincerely yours,} 
\enclosure[Attached]{curriculum vit\ae{}} 

\makelettertitle 
Text a lot of text.
\makeletterclosing

\end{document}

This gives

te
Now I want to include my handwritten signature under the sincerely yours and above my name. How can I do this?

Best Answer

I would follow the procedure listed in Adding a signature on an online job application to obtain an electronic (vectorized) version of a signature. Assume the signature is called signature.pdf. Then you would add the following code to your document preamble:

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

The above redefinition of \makeletterclosing merely inserts \includegraphics{signature}\\ before printing the first/last name. You may want to reduce the space after the closing and the beginning of the signature (currently listed above as 3em).