[Tex/LaTex] How to add a second e-mail address with moderncv

moderncv

I'm using moderncv to write my CV. I'm using the classic style and I want to add a second e-mail address. It doesn't work if I simply do that:

\mail{email1}

\mail{email2}

Is there a way to do it?

Best Answer

All you need to do is to define a newcommand (say, \emailtwo), completely analogous to \email as defined in moderncv.cls and then to modify appropriately the \makecvtitle command (as implemented in moderncvclassic.sty) to conditionally include the information for this new field:

\documentclass{moderncv}
\moderncvstyle{classic}
\makeatletter
\newcommand*{\emailtwo}[1]{\def\@emailtwo{#1}}
\renewcommand*{\makecvtitle}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputecvlengths%
  % optional detailed information box
  \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 will always be defined but could be empty
      \ifthenelse{\isundefined{\@addressstreettwo}}{}{\makenewline\addresssymbol\@addressstreettwo%
        \ifthenelse{\equal{\@addresscitytwo}{}}{}{\makenewline\@addresscitytwo}}% if \addresstreettwo is defined, \addresscitytwo will always be defined but could be empty
      \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{\@emailtwo}}{}{\makenewline\emailsymbol\emaillink{\@emailtwo}}%
      \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
      \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}%
    \end{tabular}
  }%
  % optional picture box
  \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\ \@familyname}%
    \ifthenelse{\equal{\@title}{}}{}{\\[1.25em]\titlestyle{\@title}}%
  \end{minipage}%
  \hfill%
  % detailed information
  \llap{\usebox{\makecvtitledetailsbox}}% \llap is used to suppress the width of the box, allowing overlap if the value of makecvtitlenamewidth is forced
  % optional photo
  \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*{\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~\@familyname}\@firstdetailselementfalse%
      \ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
        \ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}}%
      \ifthenelse{\isundefined{\@addressstreettwo}}{}{\makenewline\addresssymbol\@addressstreettwo%
        \ifthenelse{\equal{\@addresscitytwo}{}}{}{\makenewline\@addresscitytwo}}%
      \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}\\[1em]
  % recipient block
  \begin{minipage}[t]{.5\textwidth}
    \raggedright%
    \addressfont%
    {\bfseries\upshape\@recipientname}\\%
    \@recipientaddress%
  \end{minipage}
  % date
  \hfill% US style
%  \\[1em]% UK style
  \hbox{\today}\\[2em]% US informal style: "April 6, 2006"; UK formal style: "05/04/2006"
  % 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

\firstname{John}
\familyname{Doe}
\email{firstemail@gmail.com}
\emailtwo{secondemail@gmail.com}

\begin{document}

\makecvtitle

\end{document}

An image of the resulting document:

enter image description here