3

I have this code:

\documentclass[11pt,a4paper,sans]{moderncv}        
\usepackage{fontenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[scale=0.75]{geometry}

\moderncvstyle{casual}                             
\moderncvcolor{blue}                               

\name{John}{Doe}


\begin{document}
\makecvtitle

\hbox{
    \hspace*{0.2\textwidth}
    \textcolor{color1}{\rule{5pt}{\textwidth}}
    \hspace*{0.05\textwidth}
    \includegraphics[]{/home/toogley/bew/img/passbilder/platzhalter.png}
}

\end{document}

which produces:

output

I want to move the picture to the middle of the line. Normally, I'd try to solve that by using e.g. a figure environment. But when i use that here, i receive the error

LaTeX Error: Environment figure undefined.

According to a related question, this error message means, i can't use it. Or rather, the only solution to use a figure environment, would be to change the way moderncv works.

Therefore, my question is whether there's a way without changing how moderncv works.

0

3 Answers 3

2

Don't use \hbox; you're going to have surprises if you do.

Just shift down the rule and the picture. Don't forget to protect the end-of-lines.

\documentclass[11pt,a4paper,sans]{moderncv}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[scale=0.75]{geometry}

\moderncvstyle{casual}
\moderncvcolor{blue}

\name{John}{Doe}


\begin{document}
\makecvtitle

\noindent
\hspace{0.2\textwidth}%
\textcolor{color1}{\rule[-.5\textwidth]{5pt}{\textwidth}}%
\hspace{0.05\textwidth}%
\raisebox{-.5\height}{\includegraphics[width=2cm]{example-image-9x16}}

\end{document}

enter image description here

4
  • can you explain why i shouldn't use \hbox ? Or provide some evidence/examples for that statement?
    – toogley
    Apr 5, 2016 at 18:08
  • @toogley The comment was not specific to you: maybe you know about the quirks of \hbox, other readers may not.
    – egreg
    Apr 5, 2016 at 19:13
  • I don't, therefore I'm asking. :D
    – toogley
    Apr 5, 2016 at 19:25
  • @toogley \hbox doesn't start horizontal (paragraph) mode. Here it doesn't make much difference, in other cases it can. Try <blank line>\hbox{abc}def
    – egreg
    Apr 5, 2016 at 19:27
3

Here's a solution that might work for you using TikZ:

\documentclass[11pt,a4paper,sans]{moderncv}        
\usepackage{fontenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[scale=0.75]{geometry}

\moderncvstyle{casual}                             
\moderncvcolor{blue}                               

\name{John}{Doe}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\makecvtitle


\begin{tikzpicture}[remember picture,overlay]
  \draw[color1,line width=5pt] 
        ($(current page.north west)+(0.2\columnwidth,-2in)$)
        coordinate (TOP)
        -- ++ (0,-\textwidth)
        coordinate (BOT);
 \node[anchor=west] at ($(TOP)!0.50!(BOT)$)    {\includegraphics[width=1in]{no_you_cant}};
\end{tikzpicture}

\end{document}

enter image description here

By playing with the value !0.50! in

 \node[anchor=west] at ($(TOP)!0.25!(BOT)$)    {\includegraphics[width=1in]{no_you_cant}};

you can reposition the image to where you would like on the page.

0

Here is a suggestion using \raisebox to shift the picture upwards.

\documentclass[11pt,a4paper,sans]{moderncv}        
\usepackage{fontenc}
\usepackage[scale=0.75]{geometry}

\moderncvstyle{casual}                             
\moderncvcolor{blue}                               

\name{John}{Doe}

\begin{document}
\makecvtitle

\hbox{%
    \hspace*{0.2\textwidth}%
    \textcolor{color1}{\rule{5pt}{\textwidth}}%
    \hspace*{0.05\textwidth}%
    \raisebox{\dimexpr.5\textwidth-.5\height\relax}{%
      \includegraphics[width=1in]{example-image-golden-upright}}%
}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .