类 moderncv,风格随意:标题两行

类 moderncv,风格随意:标题两行

是否可以在页面右侧的两行上写简历标题。我解释一下:

\documentclass[11pt,a4paper,sans]{moderncv}        
\moderncvstyle{casual}                          
\moderncvcolor{blue}                            
\renewcommand{\familydefault}{\sfdefault}    
\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}
\name{John}{Doe}
\title{Resumé title\\ Second part of title}  

这不起作用,因为它一开始就进入下一行,而且不正确。有人能帮我吗?

答案1

在命令中\makecvhead你可以找到标题的定义:

  % optional title
  \ifthenelse{\equal{\@title}{}}{}{%
    \\[1.25em]\null% \null is required as there is no box on the line after \\, so glue such as \hfill (and leaders) disappear; this is in contrast to after \par, where the next line starts with an indent box (even after \noindent)
    \if@right\hfill\fi%
    \if@alternate%
      \titlestyle{\MakeLowercase\@title}%
    \else%
      \titlestyle{\@title}\fi%
    }\\[2.5em]%

为了能够在你的简历中使用命令

\title{Resumé title}
\titleb{Second part of title}

我们需要添加一个机制\titleb

在下面的 MWE 中我这样做了(请参阅标记<======以了解重要的代码更改):

\documentclass{moderncv}

\moderncvstyle{casual}
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}


\makeatletter
\newcommand*{\titleb}[1]{\def\@titleb{#1}} % <==========================

\renewcommand*{\makecvhead}{% TODO: use \@initializecommand, which requires modifying its definition to handle \par
  % recompute lengths (in case we are switching from letter to resume, or vice versa)
  \recomputecvlengths%
  % optional picture (pre-rendering)
  \@initializebox{\makecvheadpicturebox}%
  \savebox{\makecvheadpicturebox}{%
    \ifthenelse{\isundefined{\@photo}}%
      {}%
      {%
       \setlength\fboxrule{\@photoframewidth}%
       \ifdim\@photoframewidth=0pt%
         \setlength{\fboxsep}{0pt}\fi%
       {\color{color1}\framebox{\includegraphics[width=\@photowidth]{\@photo}}}}}%
  % name (pre-rendering)
  \@initializelength{\makecvheadpicturewidth}%
  \settowidth{\makecvheadpicturewidth}{\usebox{\makecvheadpicturebox}}%
  \@initializebox{\makecvheadnamebox}%
  \savebox{\makecvheadnamebox}{%
    \parbox[b]{\textwidth-\makecvheadpicturewidth}{%
      \if@left\raggedright\fi%
      \if@right\raggedleft\fi%
      \namefont%
      \if@alternate% alternate design: first- and lastname in lowercase with no space in between (distinction is made by color difference)
        {\color{color2!50}\MakeLowercase\@firstname}{\color{color2}\MakeLowercase\@lastname}%
      \else% default design: first- and lastname as given with a space in between
        {\color{color2!50}\@firstname} {\color{color2}\@lastname}\fi}}%
  % rendering
  \if@left%
    \usebox{\makecvheadnamebox}%
    \usebox{\makecvheadpicturebox}\fi
  \if@right%
    \usebox{\makecvheadpicturebox}%
    \usebox{\makecvheadnamebox}\fi\\[-.35em]%
  {\color{color2!50}\rule{\textwidth}{.25ex}}%
  % optional detailed information
  \if@details{%
    \\\null%
    \addressfont\color{color2}%
    \ifthenelse{\isundefined{\@addressstreet}}{}{\addtomakeheaddetails{\addresssymbol\@addressstreet}%
      \ifthenelse{\equal{\@addresscity}{}}{}{\addtomakeheaddetails[~--~]{\@addresscity}}% if \addresstreet is defined, \addresscity and \addresscountry will always be defined but could be empty
      \ifthenelse{\equal{\@addresscountry}{}}{}{\addtomakeheaddetails[~--~]{\@addresscountry}}%
        \flushmakeheaddetails\@firstmakeheaddetailselementtrue\\\null}%
    \collectionloop{phones}{% the key holds the phone type (=symbol command prefix), the item holds the number
      \addtomakeheaddetails{\csname\collectionloopkey phonesymbol\endcsname\collectionloopitem}}%
    \ifthenelse{\isundefined{\@email}}{}{\addtomakeheaddetails{\emailsymbol\emaillink{\@email}}}%
    \ifthenelse{\isundefined{\@homepage}}{}{\addtomakeheaddetails{\homepagesymbol\httplink{\@homepage}}}%
    \collectionloop{socials}{% the key holds the social type (=symbol command prefix), the item holds the link
      \addtomakeheaddetails{\csname\collectionloopkey socialsymbol\endcsname\collectionloopitem}}%
    \ifthenelse{\isundefined{\@extrainfo}}{}{\addtomakeheaddetails{\@extrainfo}}%
    \flushmakeheaddetails}\fi% need to force a \par after this to avoid weird spacing bug at the first section if no blank line is left after \makehead
  % optional title
  \ifthenelse{\equal{\@title}{}}{}{%
    \\[1.25em]\null% \null is required as there is no box on the line after \\, so glue such as \hfill (and leaders) disappear; this is in contrast to after \par, where the next line starts with an indent box (even after \noindent)
    \if@right\hfill\fi%
    \if@alternate%
      \titlestyle{\MakeLowercase\@title}%
    \else%
      \titlestyle{\@title}\fi%
    }%\\%[2.5em]% <=====================================================
  \ifthenelse{\isundefined{\@titleb}}{}{% <=============================
    \\[.25em]\null% \null is required as there is no box on the line after \\, so glue such as \hfill (and leaders) disappear; this is in contrast to after \par, where the next line starts with an indent box (even after \noindent)
    \if@right\hfill\fi%
    \if@alternate%
      \titlestyle{\MakeLowercase\@titleb}%
    \else%
      \titlestyle{\@titleb}\fi%
    }\\[2.5em]% <=======================================================
  % optional quote
  \ifthenelse{\isundefined{\@quote}}%
    {}%
    {{\null\hfill%
      \begin{minipage}{\quotewidth}%
        \centering%
        \quotestyle{\@quote}%
      \end{minipage}\hfill\null\\[2.5em]}}%
  \par}% to avoid weird spacing bug at the first section if no blank line is left after \maketitle

\makeatother

\name{John}{Doe}

\title{Resumé title}
\titleb{Second part of title}


\begin{document}

\makecvtitle

\end{document}

结果如下:

生成的 pdf

优点是您将获得通常的布局,而没有或没有任何关于错误标记\titleb的警告,例如......hyperref\\

答案2

您可以使用以下命令人为地对齐堆叠标题:

\title{Resumé title \\ \mbox{}\hfill Second part of title}

你会收到一些警告hyperref抱怨非 PDF 标记(如\\\hfill),但您可以放心地忽略这些。

在此处输入图片描述

\documentclass{moderncv}

\moderncvstyle{casual}
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}

\name{John}{Doe}
\title{Resumé title \\ \mbox{}\hfill Second part of title}

\begin{document}

\makecvtitle

\end{document}

如果顶部没有任何下降部分\title(如上例所示),请\strut在第一行添加:

在此处输入图片描述

\title{Resumé title \strut \\ \mbox{}\hfill Second part of title}

相关内容