Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like that the picture and the name, personal information and picture appear at the same height, instead of the picture above like here:

\documentclass{moderncv}
\usepackage{etoolbox}

\moderncvstyle{classic}
\moderncvcolor{green}

\patchcmd{\makecvtitle}{[b]}{[t]}{}{}% For tabular
\patchcmd{\makecvtitle}{[b]}{[t]}{}{}% For minipage

\setlength{\makecvtitlenamewidth}{12cm}
\renewcommand*{\namefont}{\fontsize{24}{29}\mdseries\upshape}

\firstname{Manuel}
\familyname{Fern\'andez-P\'erez}
\title{CV}
\address{street and number}{postcode city}
\mobile{+1~(234)~567~890}
\phone{+2~(345)~678~901}
\fax{+3~(456)~789~012}
\email{manuel@fernandez-perez-galdos.com}
\homepage{www.johndoe.com}
\photo[64pt]{picture}
\begin{document}

\makecvtitle
\section{Education}
\cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}  \cventry{year--year}{Degree}{Institution}{City}{\textit{Grade}}{Description}

\end{document}
share|improve this question
    
This question clarifies the previous question tex.stackexchange.com/questions/80428/… and leads here to a better result. –  strpeter Oct 8 '13 at 14:04
add comment

1 Answer

up vote 6 down vote accepted

Well, it's a bit tricky due to how \maketitle is composed. You don't know it, but TeX is doing exactly what you are asking him to do: aligning the different elements at their top. But the trick is that LaTeX aligns on their top baseline, not their utmost top border. If you look carefully, you can see that the baseline of your title (the first line of a minipage that contains your name and your title) and the first line of a tabular) are perfectly aligned (the red line was added to show the alignment):

maketitle aligned to the top baseline

Why LaTeX sometimes take the first or the last line of a box as its reference point is another topic :)


Back to your issue, if you simply remove your two lines

\patchcmd{\makecvtitle}{[b]}{[t]}{}{}

your name, title, personal information and picture will all be aligned (to the bottom baseline).

maketitle aligned to the bottom baseline


Now if you want these aligned bottom to the baseline of your name, keep the line. You now know from my first paragraph that the items are actually aligned and that the only thing you need to do, is to shift that personal information box a few "lines" to the top.
Start by getting the height and depth of the information box:

\the\ht\makecvtitledetailsbox
\the\dp\makecvtitledetailsbox

which is equal to 84pt in your example (it is equal to 6 x 14pt, the interline spacing of \addressfont, as one could expect given \addressfont is typeset in \normalsize). Then use a trick to shift the box:

\address{\vspace{-84pt}\makenewline{}street and number}{postcode city}

and now everything is perfectly aligned to the bottom (note that I only kept one of your \patchcmd{\makecvtitle}{[b]}{[t]}{}{} lines):

maketitle aligned to the bottom of the name baseline


If you want to align the elements to the top of their boxes (causing unaligned baselines), I have only found an ugly solution: redefine \makecvtitle to enable you to shift the information and picture vertically, and adjust the shift to get what you desire.

How much should you shift? Well, you can probably calculate a theoretical shift comparing the height of the boxes, but as the upper most line of the boxes are not of the same black density (different glyph extenders vs a colored line with white space), you should also take into account optical effects...

You could also be lazzy and notive by trial an error that 17pt is probably good enough :)
So remove all the hacks, add the following to your preamble

\makeatletter
\renewcommand*{\makecvtitle}{%
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputecvlengths%
  % optional detailed information box
  \newbox{\makecvtitledetailsbox}%
  \savebox{\makecvtitledetailsbox}{%
    \addressfont\color{color2}%
    \begin{tabular}[t]{@{}r@{}}%
      \ifthenelse{\isundefined{\@addressstreet}}{}{\makenewline\addresssymbol\@addressstreet%
        \ifthenelse{\equal{\@addresscity}{}}{}{\makenewline\@addresscity}}% if \addresstreet is defined, \addresscity will always be defined but could be empty
      \ifthenelse{\isundefined{\@mobile}}{}{\makenewline\mobilesymbol\@mobile}%
      \ifthenelse{\isundefined{\@phone}}{}{\makenewline\phonesymbol\@phone}%
      \ifthenelse{\isundefined{\@fax}}{}{\makenewline\faxsymbol\@fax}%
      \ifthenelse{\isundefined{\@email}}{}{\makenewline\emailsymbol\emaillink{\@email}}%
      \ifthenelse{\isundefined{\@homepage}}{}{\makenewline\homepagesymbol\httplink{\@homepage}}%
      \ifthenelse{\isundefined{\@extrainfo}}{}{\makenewline\@extrainfo}%
    \end{tabular}
  }%
  % optional photo (pre-rendering)
  \newbox{\makecvtitlepicturebox}%
  \savebox{\makecvtitlepicturebox}{%
    \ifthenelse{\isundefined{\@photo}}%
    {}%
    {%
      \hspace*{\separatorcolumnwidth}%
      \color{color1}%
      \setlength{\fboxrule}{\@photoframewidth}%
      \ifdim\@photoframewidth=0pt%
        \setlength{\fboxsep}{0pt}\fi%
  \framebox{\includegraphics[width=\@photowidth]{\@photo}}}}%
  % name and title
  \newlength{\makecvtitledetailswidth}\settowidth{\makecvtitledetailswidth}{\usebox{\makecvtitledetailsbox}}%
  \newlength{\makecvtitlepicturewidth}\settowidth{\makecvtitlepicturewidth}{\usebox{\makecvtitlepicturebox}}%
  \ifthenelse{\lengthtest{\makecvtitlenamewidth=0pt}}% check for dummy value (equivalent to \ifdim\makecvtitlenamewidth=0pt)
    {\setlength{\makecvtitlenamewidth}{\textwidth-\makecvtitledetailswidth-\makecvtitlepicturewidth}}%
    {}%
  \begin{minipage}[t]{\makecvtitlenamewidth}%
    \namestyle{\@firstname\ \@familyname}%
    \ifthenelse{\equal{\@title}{}}{}{\\[1.25em]\titlestyle{\@title}}%
  \end{minipage}%
  \hfill%
  % detailed information
  \llap{%
    \begin{minipage}[t]{\makecvtitledetailswidth}%
    \vspace*{-17pt}%
    \usebox{\makecvtitledetailsbox}%
    \end{minipage}}% \llap is used to suppress the width of the box, allowing overlap if the value of makecvtitlenamewidth is forced
  % optional photo (rendering)
  \begin{minipage}[t]{\makecvtitlepicturewidth}%
    \vspace*{-17pt}%
    \vbox to 0pt{%
      \usebox{\makecvtitlepicturebox}%
    }%
  \end{minipage}\\[2.5em]%
  % optional quote
  \ifthenelse{\isundefined{\@quote}}%
    {}%
    {{\centering\begin{minipage}{\quotewidth}\centering\quotestyle{\@quote}\end{minipage}\\[2.5em]}}%
  \par}% to avoid weird spacing bug at the first section if no blank line is left after \makecvtitle
\makeatother

and enjoy the result:

maketitle aligned to the uppermost top "corner"

share|improve this answer
1  
Thanks. What should I do to align the top corner of the name with street and number" ? –  inquisitor Nov 10 '12 at 20:07
1  
@inquisitor That's rather tricky, as everything TeX / typography works relative to a baseline. Aligning "corners" and misaligning baselines will give your readers a headache in my opinion. But If that's what you want, I've edited my answer above. –  Xavier Nov 11 '12 at 6:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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