ModernCV – Adding a Picture in ModernCV

moderncv

I am new to LaTeX. I am writing a CV using the moderncv package with style banking. I want to add a photo. After I run the compile command it exits normally but the photo doesn't appear on the page.

My code is following:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{banking} 
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}
\usepackage[scale=0.8]{geometry}
\usepackage{import}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{tabularx}

\name{Name}{Last Name} % My name is quite long, can it be the problem?
\title{Resume}
\address{Address}   
\phone[mobile]{my_number}    
\email{my_e-mail}  
\photo[64pt][0pt]{name_of_the_phot}   
\setlength\tabcolsep{10pt}
\begin{document}

\makecvtitle   

\end{document}

Any help how to add photo and change its position afterwards? I want it to appear on the right or left side.

Thanks in advance.

Best Answer

To get the image on the right you can patch the existing method of creating the head for the cv.

To get the image on the left you need to completly rewrite the method of creating the head by using a tabular (for example).

Because I think it looks not very nice having the image on the left I show you a possibility to get the image on the right side.

With the following patch

\patchcmd{\makehead}% <cmd>
  {\\[2.5em]}% <search>
  {\hfill\raisebox{-1.9cm}[0pt][0pt]{\includegraphics[width=.18\textwidth]{example-image-10x16}}\\[2.5em]}% <replace>
  {}{}% <success><failure>

you add the image on the right side. The position of the image is corrected with \raisebox{-1.9cm}[0pt][0pt]{. Change 1.9cm for your needs.

The width of the image is given by width=.18\textwidth. That comes because the layout of the header has a limited length of the head of \setlength{\makeheaddetailswidth}{0.8\textwidth}, that means 0.8\textwidth

If you want or need to change this use the following patch first:

\patchcmd{\makehead}% <cmd>
  {\setlength{\makeheaddetailswidth}{0.8\textwidth}}% <search>
  {\setlength{\makeheaddetailswidth}{0.7\textwidth}}% <replace> % <=============
  {}{}% <success><failure>

Change the used width to your need.

The following MWE

\documentclass[11pt,a4paper,sans]{moderncv}

\moderncvstyle{banking} % head 3 body 3 
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}
\usepackage[scale=0.8]{geometry}
\usepackage{import}
\usepackage{booktabs}
\usepackage{xcolor}
\usepackage{tabularx}

\name{John}{Doe}
\title{Resumé title}
\address{street and number}{postcode city}{country}
\phone[mobile]{+1~(234)~567~890}
\phone[fixed]{+2~(345)~678~901}
\phone[fax]{+3~(456)~789~012}
\email{john@doe.org}
\homepage{www.johndoe.com}
\social[linkedin]{john.doe}
\social[twitter]{jdoe}
\social[github]{jdoe}
\extrainfo{additional information}
\quote{Some quote}

\setlength\tabcolsep{10pt}

%\patchcmd{\makehead}% <cmd>
  %{\setlength{\makeheaddetailswidth}{0.8\textwidth}}% <search>
  %{\setlength{\makeheaddetailswidth}{0.7\textwidth}}% <replace>
  %{}{}% <success><failure>

\patchcmd{\makehead}% <cmd>
  {\\[2.5em]}% <search>
  {\hfill\raisebox{-1.9cm}[0pt][0pt]{\includegraphics[width=.18\textwidth]{example-image-10x16}}\\[2.5em]}% <replace>
  {}{}% <success><failure>


\begin{document}

\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution--3}{City--4}{\textit{Grade}--5}{Description--6}  % arguments 3 to 6 can be left empty
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\section{Master thesis}
\cvitem{title}{\emph{Title}}
\cvitem{supervisors}{Supervisors}
\cvitem{description}{Short thesis abstract}

\section{Experience}
\subsection{Vocational}
\cventry{year--year}{Job title}{Employer}{City}{}{General description 
  no longer than 1--2 lines.\newline{}%
Detailed achievements:%
\begin{itemize}%
\item Achievement 1;
\item Achievement 2, with sub-achievements:
  \begin{itemize}%
  \item Sub-achievement (a);
  \item Sub-achievement (b), with sub-sub-achievements (don't do this!);
    \begin{itemize}
    \item Sub-sub-achievement i;
    \item Sub-sub-achievement ii;
    \item Sub-sub-achievement iii;
    \end{itemize}
  \item Sub-achievement (c);
  \end{itemize}
\item Achievement 3.
\end{itemize}}
\cventry{year--year}{Job title}{Employer}{City}{}{Description 
  line 1\newline{}Description line 2}
\subsection{Miscellaneous}
\cventry{year--year}{Job title}{Employer}{City}{}{Description}

\end{document}

gives you the resulting page:

enter image description here

BTW: The given code compiles if you are using moderncv, version 2.