# How to insert a logo in moderncv and keep it on the right side of the page?

Ok the title is not exactly clear, so I will try to be clearer here.

I have succesfully added a logo in a cventry using the answer provided in this tread. The command that I used is

\newcommand*{\cventrylogo}[8][.25em]{%
\cvitem[#1]{#2}{%
{\bfseries#3}%
\ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
\ifthenelse{\equal{#5}{}}{}{, #5}%
\ifthenelse{\equal{#6}{}}{}{, #6.}%
\ifthenelse{\equal{#7}{}}{}{\hfill \includegraphics[scale=0.25]{#7}}%
\strut%
\ifx&#8&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#8\end{minipage}}\fi}}


This works, but the result that I get is in the image that follows:

As you can see, the logo is there but if the text preceding it is long, it gets pushed to the next line. I'd like to avoid that behavior and have the logo fixed on the right side of the page, with the text naturally going on the next line.

I've prepared an image of what I'd like to achieve:

How should I modify the command to get this result?

Here is a minimum code example if you need to test things:

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

\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.85]{geometry}

\name{John}{Doe}
\phone[mobile]{+1234567890}
\phone[fixed]{+1234567890}
\email{email@emal.com}
\photo[64pt][0.4pt]{picture}

%cventrylogo
\newcommand{\cventrylogo}[9][.25em]{%
\cvitem[#1]{#2}{%
{\bfseries#3}%
\ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
\ifthenelse{\equal{#5}{}}{}{, #5}%
\ifthenelse{\equal{#6}{}}{}{, #6.}%
\ifthenelse{\equal{#7}{}}{}{%
\ifthenelse{\equal{#8}{}}{}{\hfill \raisebox{-0.5\height}{\includegraphics[width=#8]{#7}}}}%
\strut%
\ifx&#9&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#9\end{minipage}}\fi} }
\begin{document}

\makecvtitle

\section{Work Experience}

\section{Education}
\cventrylogo{Date1 - Date2}{Very long name just to make things clearer}{Name of the institution}{Address of the institution}{}{logo}{16mm}{Very long and interesting description of what I did there}

\end{document}


There you go:

I used a minipage approach. First I check if the argument #7 is present, if it is, create a minipage with width \linewidth-#8-1em (the 1em is atrbitrary, just to keep a small space between the text and the image).

Then the content is typeset normally.

Then, another check is repeated of the existence of #7 and, if positive, the first minipage is closed and another with width #8 is opened and the image is placed.

### Edit:

I had to patch the \cvitem macro to correct the vertical alignment. Because I used [t]op aligned minipages on the right side of the \cvitem, LaTeX aligned the baseline of the left side with a \vspace{0pt}, which caused the misalignment. So I patched the \cvitem macro to include a minipage with the same [t]op alignment.

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

\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.85]{geometry}

\name{John}{Doe}
\phone[mobile]{+1234567890}
\phone[fixed]{+1234567890}
\email{email@emal.com}
\photo[64pt][0.4pt]{example-image}

\expandafter\patchcmd\csname\string\cvitem\endcsname
{\hintstyle{#2}}
{\hintstyle{\begin{minipage}[t]{\dimexpr\linewidth-2\tabcolsep\relax}\vspace{0pt}#2\end{minipage}}}
{}
{}%

%cventrylogo
\newcommand{\cventrylogo}[9][.25em]{%
\cvitem[#1]{#2}{%
\ifthenelse{\equal{#7}{}}%
{}{%                                        V-V arbitrary space
\begin{minipage}[t]{\dimexpr\linewidth-#8-1em}%
\vspace{0pt}%
}%
{\bfseries#3}%
\ifthenelse{\equal{#4}{}}{}{, {\slshape#4}}%
\ifthenelse{\equal{#5}{}}{}{, #5}%
\ifthenelse{\equal{#6}{}}{}{, #6.}%
\strut%
\ifx&#9&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#9\end{minipage}}\fi
\ifthenelse{\equal{#7}{}}%
{}{%
\end{minipage}\hfill%
\begin{minipage}[t]{#8}%
\vspace{0pt}%
\includegraphics[width=#8]{#7}%
\end{minipage}%
}%
} }
\begin{document}

\makecvtitle

\section{Work Experience}

\section{Education}
\cventrylogo{Date1 - Date2}{Very long name just to make things clearer}{Name of the institution}{Address of the institution}{}{example-image}{16mm}{Very long and interesting description of what I did there}

\end{document}

• Thanks this is great! Just a quick question: as you can see from the image you uploaded, the description is not vertically aligned with the date anymore, is there any way to change this behavior and keep the vertical alignment? – user152966 Feb 6 '18 at 19:01
• @randomlygenned Done! – Phelype Oleinik Feb 6 '18 at 19:51
• this fixes that problem but cause every other element to be vertically misaligned. Like the section titles (they should be at the same level of the blue lines) and every other entry that does not use the \cventrylogo command, like a normal \cventry. Thanks a lot though, I will try and see if I can work something out! – user152966 Feb 6 '18 at 22:17
• Ok I found a solution. If anyone is interested, I inserted a negative value into \vspace{}, so that the \minipage is shifted up. The value that works for me is -8pt. It probably isn't the best or most elegant solution, but it works! – user152966 Feb 6 '18 at 22:25