对齐简历中的姓名、数据和图片

对齐简历中的姓名、数据和图片

我希望图片和姓名、个人信息和图片出现在同一个高度,而不是像这里一样出现在图片上面:

\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{[email protected]}
\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}

答案1

嗯,这有点棘手,因为\maketitle的组成方式。你不知道,但 TeX 正在做你要求他做的事情:将不同的元素对齐到顶部。但诀窍是 LaTeX 对齐到顶部基线,而不是它们的最大上边框。如果仔细观察,您会发现标题的基线(minipage包含您的姓名和头衔的 的第一行)和 的第一行tabular完全对齐(添加了红线以显示对齐):

使标题与顶部基线对齐

为什么 LaTeX 有时会将框的第一行或最后一行作为其参考点是另一个话题:)


回到你的问题,如果你只是删除两行

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

您的姓名、职称、个人信息和照片都将对齐(到底部基线)。

maketitle 与底部基线对齐


现在,如果您希望这些对齐到您姓名的基线,请保留该线。现在您从我的第一段知道这些项目实际上是对齐的,并且您唯一需要做的就是将个人信息框向上移动几“行”。
首先获取信息框的高度和深度:

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

在您的示例中等于84pt(它等于6 x 14pt,行间距为\addressfont,正如人们所期望的那样,因为\addressfont排版为\normalsize)。然后使用一个技巧来移动框:

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

现在所有内容都与底部完美对齐(请注意,我只保留了其中一行\patchcmd{\makecvtitle}{[b]}{[t]}{}{}):

maketitle 与名称基线底部对齐


如果您想将元素对齐到其框的顶部(导致基线不对齐),我只找到了一个丑陋的解决方案:重新定义\makecvtitle以使您能够垂直移动信息和图片,并调整移动以获得您想要的结果。

您应该偏移多少?好吧,您可能可以通过比较框的高度来计算理论偏移,但由于框的最上行不是相同的黑色密度(不同的字形扩展器与带有白色空间的彩色线),您还应该考虑光学效果...

你也可以偷懒,通过反复试验,发现错误17pt可能已经足够好了。
所以,去掉所有的 hack,在你的序言中添加以下内容

\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

并享受结果:

使标题与最上方的“角”对齐

相关内容