cventry 中的换行符

cventry 中的换行符

我正在使用乳胶风格的 moderncv 和命令\cventry,其定义如下:

% makes a typical resume job / education entry
% usage: \cventry[spacing]{years}{degree/job title}{institution/employer}{localization}{optionnal: grade/...}{optional: comment/job description}
\newcommand*{\cventry}[7][.25em]{}

我正在用它为我目前的工作创建简历条目,但是,我的机构/雇主条目太长,一行放不下,导致水平盒子溢出。我该如何将其换行到下一行?

MWE 如下:

\documentclass[11pt,a4paper,sans]{moderncv}       
\moderncvstyle{banking}                           
\moderncvcolor{blue}                              
\usepackage[utf8]{inputenc}                     
\usepackage[scale=0.82]{geometry}
\usepackage{import}
\name{Joe}{Bloggs}
\address{Somewhere Street, Somewhere}{12345}{Country}

\begin{document}

\makecvtitle

\section{Current Employment}

\vspace{6pt}

\begin{itemize}

\item{\cventry{date--present}{Job Title}{Job name}{Long name of my current employer which causes an overfull hbox and runs off the edge of the page}{}{}{\vspace{3pt}}}

\end{itemize}

\end{document}

输出如下所示:

溢出水平盒

理想情况下,我想将溢出的 Hbox 换到新行(仍然右对齐,以便“我当前雇主的长名称......”不会与左侧的 Hbox(“职位”)冲突并超出右侧边缘。 有办法做到这一点吗?

答案1

当前的命令定义\cventry不允许你得到你想要的。但你可以\mycventry像这样定义一个新命令:

\newcommand*{\mycventry}[8][.25em]{ % <=================================
  \begin{tabular*}{\maincolumnwidth}{l@{\extracolsep{\fill}}r}% 
  {\bfseries #4} & {\bfseries #5}\\% 
   & {\bfseries #8} \\ % <==============================================
  {\itshape #3\ifthenelse{\equal{#6}{}}{}{, #6}} & {\itshape #2}\\% 
  \end{tabular*}% 
  \ifx&#7&% 
  \else{\\% 
  \begin{minipage}{\maincolumnwidth}% 
    \small#7% 
  \end{minipage}}\fi% 
  \par\addvspace{#1}}

如您所见,我添加了第 8 个参数 ( #8) 来获取所需文本的第二部分。因此,参数 5 ( #5) 获取文本的第一部分,参数 8 获取文本的第二部分。如果您愿意,可以更改使用的参数以获取两个文本部分,例如参数 5 和 6,但随后您必须更改新命令\mycventry。您的情况非常特殊,我认为上面给出的解决方案已经足够好了……您可以像这样使用:

\item \mycventry{date--present--2}%
  {Job Title--3}%
  {Job name--4}%
  {Long name of my current employer whichcauses an--5}%
  {--6}%
  {--7}%
  { overfull hbox and runs off the edge of the page--8}% <=========================

完整代码如下

\documentclass[11pt,a4paper,sans]{moderncv}

\moderncvstyle{banking}
\moderncvcolor{blue}

\usepackage[utf8]{inputenc}
\usepackage[scale=0.82]{geometry}
\usepackage{import}

\name{Joe}{Bloggs}
\address{Somewhere Street, Somewhere}{12345}{Country}

\newcommand*{\mycventry}[8][.25em]{ % <=================================
  \begin{tabular*}{\maincolumnwidth}{l@{\extracolsep{\fill}}r}% 
  {\bfseries #4} & {\bfseries #5}\\% 
   & {\bfseries #8} \\ % <==============================================
  {\itshape #3\ifthenelse{\equal{#6}{}}{}{, #6}} & {\itshape #2}\\% 
  \end{tabular*}% 
  \ifx&#7&% 
  \else{\\% 
  \begin{minipage}{\maincolumnwidth}% 
    \small#7% 
  \end{minipage}}\fi% 
  \par\addvspace{#1}}


\begin{document}

\makecvtitle

\section{Current Employment}

\vspace{6pt}

\begin{itemize}

%\item \cventry{date--present--2}{Job Title--3}{Job name--4}{Long name of my current employer whichcauses an overfull hbox \\ and runs off the edge of the page--5}{--6}{--7}%{\vspace{3pt}}

\item \mycventry{date--present--2}{Job Title--3}{Job name--4}{Long name of my current employer whichcauses an--5}{--6}{--7}{ overfull hbox and runs off the edge of the page--8}% <=========================

\item \cventry{year--year--2}{Degree--3}{Institution--4}{City--5}{\textit{Grade}--6}{Description--7}  % arguments 4 to 7 can be left empty

\item \cventry{year--year--2}{Degree--3}{}{}{}{}  % arguments 4 to 7 can be left empty

\end{itemize}

\end{document}

您将获得以下结果 pdf:

生成的 pdf

相关内容