[Tex/LaTex] Adding pictures to moderncv

aligngraphicsmoderncv

I want to add my institution logos to my CV but unfortunately they don't appear in right place. How should I edit the code to make the picture appear right above the city without making the "institution" to go down, i.e. to make it flow there aligned with other information?
enter image description here

 %% start of file `template.tex'.
%% Copyright 2006-2013 Xavier Danaux (xdanaux@gmail.com).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License version 1.3c,
% available at http://www.latex-project.org/lppl/.


\documentclass[11pt,a4paper,sans]{moderncv}        % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman')

% moderncv themes
\moderncvstyle{banking}                            % style options are 'casual' (default), 'classic', 'oldstyle' and 'banking'
\moderncvcolor{red}                                % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
%\renewcommand{\familydefault}{\sfdefault}         % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name
%\nopagenumbers{}                                  % uncomment to suppress automatic page numbering for CVs longer than one page

% character encoding
\usepackage[utf8]{inputenc}                       % if you are not using xelatex ou lualatex, replace by the encoding you are using
%\usepackage{CJKutf8}                              % if you need to use CJK to typeset your resume in Chinese, Japanese or Korean

% adjust the page margins
\usepackage[scale=0.75]{geometry}
%\setlength{\hintscolumnwidth}{3cm}                % if you want to change the width of the column with the dates
%\setlength{\makecvtitlenamewidth}{10cm}           % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks...

% personal data
\name{John}{Doe}
\title{Resumé title}                               % optional, remove / comment the line if not wanted
\address{street and number}{postcode city}{country}% optional, remove / comment the line if not wanted; the "postcode city" and and "country" arguments can be omitted or provided empty
\phone[mobile]{+1~(234)~567~890}                   % optional, remove / comment the line if not wanted
\phone[fixed]{+2~(345)~678~901}                    % optional, remove / comment the line if not wanted
\phone[fax]{+3~(456)~789~012}                      % optional, remove / comment the line if not wanted
\email{john@doe.org}                               % optional, remove / comment the line if not wanted
\homepage{www.johndoe.com}                         % optional, remove / comment the line if not wanted
\extrainfo{additional information}                 % optional, remove / comment the line if not wanted
\photo[64pt][0.4pt]{picture}                       % optional, remove / comment the line if not wanted; '64pt' is the height the picture must be resized to, 0.4pt is the thickness of the frame around it (put it to 0pt for no frame) and 'picture' is the name of the picture file
\quote{Some quote}                                 % optional, remove / comment the line if not wanted

% to show numerical labels in the bibliography (default is to show no labels); only useful if you make citations in your resume
%\makeatletter
%\renewcommand*{\bibliographyitemlabel}{\@biblabel{\arabic{enumiv}}}
%\makeatother
%\renewcommand*{\bibliographyitemlabel}{[\arabic{enumiv}]}% CONSIDER REPLACING THE ABOVE BY THIS

% bibliography with mutiple entries
%\usepackage{multibib}
%\newcites{book,misc}{{Books},{Others}}
%----------------------------------------------------------------------------------
%            content
%----------------------------------------------------------------------------------
\begin{document}
%\begin{CJK*}{UTF8}{gbsn}                          % to typeset your resume in Chinese using CJK
%-----       resume       ---------------------------------------------------------
\makecvtitle

\section{Education}
\cventry{year--year}{Degree}{Institution}{\includegraphics[scale=0.5]{picture}City}{\textit{Grade}}{Description}  % arguments 3 to 6 can be left empty
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\end{document}


%% end of file `template.tex'.

Best Answer

I see two problems you're trying to deal with:

  1. How to add a line break in the "city" field?
  2. How to (vertically) mid-align institution name and the logo & city name?

The definition of the \cventry command involves a tabular* environment, and so it's not very friendly to the use of line breaks. To work around this, one can put both the logo and the city name in a TikZ node, which allows line breaks, and input the TikZ picture in the "city" field. To implement this, you can use define the following macro:

\newcommand\logocity[3][]{
  \tikz[baseline=(n.center)]
  \node(n)[align=center,inner sep=0,outer sep=0]{\includegraphics[#1]{#2}\\[1ex]#3};
}

which takes three arguments:

  • the first optional argument specifies options to the \includegraphics command
  • the second argument gives the name of the image file
  • the third argument gives the name of the city

Note that the option [baseline=(n.center)] to \tikz causes the baseline of the TikZ picture to the center of the node, thus solving the second problem as well.

Full Code

Notice that I've loaded the tikz package (the mwe package is loaded just to provide the image used in this example. You don't need it.)

\documentclass[11pt,a4paper,sans]{moderncv}        % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman')

\usepackage{tikz,mwe}

% moderncv themes
\moderncvstyle{banking}                            % style options are 'casual' (default), 'classic', 'oldstyle' and 'banking'
\moderncvcolor{red}                                % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
%\renewcommand{\familydefault}{\sfdefault}         % to set the default font; use '\sfdefault' for the default sans serif font, '\rmdefault' for the default roman one, or any tex font name
%\nopagenumbers{}                                  % uncomment to suppress automatic page numbering for CVs longer than one page

% character encoding
\usepackage[utf8]{inputenc}                       % if you are not using xelatex ou lualatex, replace by the encoding you are using
%\usepackage{CJKutf8}                              % if you need to use CJK to typeset your resume in Chinese, Japanese or Korean

% adjust the page margins
\usepackage[scale=0.75]{geometry}
%\setlength{\hintscolumnwidth}{3cm}                % if you want to change the width of the column with the dates
%\setlength{\makecvtitlenamewidth}{10cm}           % for the 'classic' style, if you want to force the width allocated to your name and avoid line breaks. be careful though, the length is normally calculated to avoid any overlap with your personal info; use this at your own typographical risks...

% personal data
\name{John}{Doe}
\title{Resumé title}                               % optional, remove / comment the line if not wanted
\address{street and number}{postcode city}{country}% optional, remove / comment the line if not wanted; the "postcode city" and and "country" arguments can be omitted or provided empty
\phone[mobile]{+1~(234)~567~890}                   % optional, remove / comment the line if not wanted
\phone[fixed]{+2~(345)~678~901}                    % optional, remove / comment the line if not wanted
\phone[fax]{+3~(456)~789~012}                      % optional, remove / comment the line if not wanted
\email{john@doe.org}                               % optional, remove / comment the line if not wanted
\homepage{www.johndoe.com}                         % optional, remove / comment the line if not wanted
\extrainfo{additional information}                 % optional, remove / comment the line if not wanted
\photo[64pt][0.4pt]{picture}                       % optional, remove / comment the line if not wanted; '64pt' is the height the picture must be resized to, 0.4pt is the thickness of the frame around it (put it to 0pt for no frame) and 'picture' is the name of the picture file
\quote{Some quote}                                 % optional, remove / comment the line if not wanted

% to show numerical labels in the bibliography (default is to show no labels); only useful if you make citations in your resume
%\makeatletter
%\renewcommand*{\bibliographyitemlabel}{\@biblabel{\arabic{enumiv}}}
%\makeatother
%\renewcommand*{\bibliographyitemlabel}{[\arabic{enumiv}]}% CONSIDER REPLACING THE ABOVE BY THIS

% bibliography with mutiple entries
%\usepackage{multibib}
%\newcites{book,misc}{{Books},{Others}}
%----------------------------------------------------------------------------------
%            content
%----------------------------------------------------------------------------------
\begin{document}
%\begin{CJK*}{UTF8}{gbsn}                          % to typeset your resume in Chinese using CJK
%-----       resume       ---------------------------------------------------------
\makecvtitle

\newcommand\logocity[3][]{
  \tikz[baseline=(n.center)]
  \node(n)[align=center,inner sep=0,outer sep=0]{\includegraphics[#1]{#2}\\[1ex]#3};
}

\section{Education}
\cventry{year--year}{Degree}{Institution}{\logocity[scale=.2]{image}{Some City}}{\textit{Grade}}{Description}  % arguments 3 to 6 can be left empty
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\end{document}

Output

enter image description here


Update in reply to comment

If one wants to get nice alignment between the "city-year-image" group and the "institute-degree/grade" group, then some "hacking" of the moderncv style is involved. Based on the definition of \cventry, I define a new command called \cventrylogo, which extends \cventry by allowing for a logo entry. The command is defined as follows:

\newcommand\minitab[2][l]{\begin{tabular}[b]{#1}#2\end{tabular}}
\newcommand\tnode[2][left]{\tikz[baseline=(n.center)]\node(n)[inner sep=0,outer sep=0,align=#1]{#2};}
\newcommand*{\cventrylogo}[8][.25em]{
  \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}r}%
    \tnode{\minitab[l]{
      {\bfseries #4} \\ {\itshape #3\ifthenelse{\equal{#7}{}}{}{, #7}}
    }}
    & 
    \tnode[right]{\minitab[r]{{\bfseries #6} \\ {\itshape #2} \\ #5}} 
      \\%
  \end{tabular*}%
  \ifx&#8&%
    \else{\\\vbox{\small#8}}\fi%
  \par\addvspace{#1}}

It takes 7 arguments (plus 1 optional argument, right now I'm assuming that all 7 arguments will be used, I haven't tested the scenarios where some are omitted), and is used in the following form:

\cventrylogo{year--year}{Degree}{Institution}{\includegraphics[scale=.2]{image}}
            {City}{\textit{Grade}}{Description}

and the output looks like this:

enter image description here


Update 2

\cventrylogo can be defined so that "institute-degree/grade-description" can be mid-aligned as a group.

\newcommand\minitab[2][l]{\begin{tabular}[b]{#1}#2\end{tabular}}
\newcommand\tnode[2][left]{\tikz[baseline=(n.center)]\node(n)[inner sep=0,outer sep=0,align=#1]{#2};}
\newcommand*{\cventrylogo}[8][.25em]{
  \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}r}%
    \tnode{\minitab[l]{
      {\bfseries #4} \\ {\itshape #3\ifthenelse{\equal{#7}{}}{}{, #7}} \\ {\small#8}
    }}
    & 
    \tnode[right]{\minitab[r]{{\bfseries #6} \\ {\itshape #2} \\ #5}} 
      \\%
  \end{tabular*}%
  \par\addvspace{#1}}

Thus using \cventrylogo as in the first update produces

enter image description here

(The black lines are drawn just to show the effect of vertical alignment.)