4

I am trying to insert an image below the year in the first argument of the \cventry macro and automatically align that image both vertically and horizontally according to the space taken by the remainder of the entry. I managed to get it horizontally aligned, but not vertically, as shown below. I have tried several options with \vspace*{\fill} and other boxes, but none seem to work.

Any clues on how to achieve both vertical and horizontal alignments?

\documentclass{moderncv}

\begin{document}

\cventry{1970\\
\makebox[\hintscolumnwidth]{%
\includegraphics[height=35pt]{misc/stackexchange-black}%
}%
}
{Title}{subtitle}{}{}{text\\text\\more text\\text\\text.}{}

\end{document}

Horizontal alignment.

0

1 Answer 1

3

EDITED to auto-center vertically the image, using \Xcventry with an extra argument in which the underset material is provided as argument #1. I use the \stackunder macro to achieve it. It also can take an optional argument which will denote the gap between year and image.

In the MWE below, for the 1st entry, I use \cventry and manually center using the optional argument of \stackunder. For the 2nd-4th cases, I auto-center using \Xcventry. The last case is a vanilla \cventry with no underset.

EDITED to work with smaller images and multi-line titles and subtitles.

\documentclass{moderncv}
\moderncvstyle{classic}
\moderncvcolor{green}
\renewcommand{\familydefault}{\rmdefault}
\usepackage{stackengine}
\def\stackalignment{r}
\firstname{Andrew}
\familyname{\newline Doe}
\title{Curriculum Vitae}
\newcommand\Xcventry[8]{%
  \setbox0=\hbox{\addstackgap[.5\baselineskip]{\parbox[b]{\hintscolumnwidth}{#1}}}%
  \setbox2=\hbox{\parbox[b]{\dimexpr\linewidth-\hintscolumnwidth}{%
    \textbf{#3}, \textit{#4}.\par#7}}%
  \def\stacktype{L}%
  \edef\stackshift{\the\dimexpr.5\dimexpr\ht2+\ht0-\baselineskip}%
  \cventry{\stackunder[\stackshift]{#2}{%
    \makebox[\hintscolumnwidth]{#1}}}{#3}{#4}{#5}{#6}{#7}{#8}%
}
\begin{document}
\maketitle
% MANUALLY
\cventry{\stackunder[8pt]{1970}{\includegraphics[width=\hintscolumnwidth]{example-image}}
}
{Title}{subtitle}{}{}{text\\text\\more text\\text\\text.}{}
% \Xcventry
\Xcventry{\includegraphics[width=\hintscolumnwidth]{example-image}}{1970}
{Title Title Title Title Title Title }{subtitle subtitle subtitle subtitle }
  {}{}{text\\text\\more text\\text\\text.}{}
% \Xcventry
\Xcventry{\includegraphics[width=.5\hintscolumnwidth]{example-image}}{1970}
{Title}{subtitle}{}{}{text\\text\\more text\\text\\text.
                      \\more text\\text\\text.}{}
% \Xcventry
\Xcventry{\includegraphics[width=\hintscolumnwidth]{example-image}}{1970}
{Title Title Title Title Title Title }{subtitle subtitle subtitle subtitle }
  {}{}{text\\text\\more text\\text\\text.
                      text\\text\\more text\\text\\text.}{}
% \cventry with no figure
\cventry{1970}
{Title}{subtitle}{}{}{text\\text\\more text\\text\\text.}{}
\end{document}

enter image description here

13
  • That is a good one, but the image is not vertically centered as the text in the right hand-side grows. Is that achievable using \usepackage{stackengine}?
    – dfernan
    Apr 28, 2016 at 14:07
  • @dfernan So, just that I understand, you would like to automatically adjust the vertical location of the image to be centered to the text on the right? If manual adjustment is acceptable, the optional argument of the \stackunder provides that capability. Apr 28, 2016 at 14:11
  • Yes, that is correct. Sorry if I did not make that clear in my initial post. Anyway, if automatically centering the image is not easily done, then I guess that the manual offset would do.
    – dfernan
    Apr 28, 2016 at 14:18
  • @dfernan Please see revision. Apr 28, 2016 at 14:41
  • 1
    Your revised answer works, but the image is not properly centered when the title or the subtitle make up more than one line. The horizontal centering is also lost (for smaller images rather than width=\hintscolumnwidth). You think that this can be easily fixed?
    – dfernan
    Apr 28, 2016 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.