第一个参数的所有内容(主要是日期)\cvitem
应在奥地利左对齐 - 正如职业中心向我解释的那样。我想重新定义命令\cvitem
(例如我可以重新定义一个命令来包含它自己吗?)。
\let\oldcvitem\cvitem
\renewcommand*{\cvitem}[3][]{\oldcvitem}
我的 MWE:
\documentclass[11pt,a4paper,sans]{moderncv}
\let\oldcvitem\cvitem%
\renewcommand*{\cvitem}[3][]{\oldcvitem[#1]{\flushright{#2}}{#3}}%
\moderncvstyle{casual}
\firstname{First}
\familyname{Last}
\begin{document}
\section{Some examples}
\cvitem{Year}{Entry}
\cvitem{2001--2013}{I am a dark knight}
\end{document}
答案1
的 MWE需要添加、和moderncv
的选择。\moderncvstyle
\firstname
\familyname
最简单的调整方法\cvitem
是从 moderncvstyle 文件之一中复制其定义:
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}
\firstname{First}
\familyname{Last}
\renewcommand*{\cvitem}[3][.25em]{%
\begin{tabular}{|@{}p{\hintscolumnwidth}|@{\hspace{\separatorcolumnwidth}}|p{\maincolumnwidth}@{}|}%
\raggedleft\hintstyle{#2} &{#3}%
\end{tabular}%
\par\addvspace{#1}}
\begin{document}
\makecvtitle
\cvitem{Year}{Entry}
\end{document}
我在环境中添加了一些栏目tabular
,以便清楚地显示每个\cvitem
栏目的排版方式。
从这里,您可以自定义tabular
环境或 IT 条目。我不确定我是否完全理解了您的要求,但您可以通过\raggedleft
从表格条目中删除来将年份左对齐。
编辑:
在上述版本中,年份列明显太宽(0.15\textwidth
)。可以使用 来控制列宽\setlength{\hintscolumnwidth}{width}
。
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}
\firstname{First}
\familyname{Last}
\setlength{\hintscolumnwidth}{0.1\textwidth}
\renewcommand*{\cvitem}[3][.25em]{%
\begin{tabular}{@{}p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}@{}}%
\hintstyle{#2} &{#3}%
\end{tabular}%
\par\addvspace{#1}}
\begin{document}
\makecvtitle
\cvitem{Year}{Entry}
\end{document}
答案2
首先,我想指出的是,只要您\raggedleft
从重新定义中删除,@Pedro 的答案就可以正常工作(所以 +1)。但是,我发现\addvspace
使用的方式moderncv
相当不直观,所以如果我要模仿类对\parbox
-es 的操作,我会做得有点不同。示例:
\documentclass[11pt,a4paper,sans]{moderncv}
\usepackage[T1]{fontenc}
\usepackage{lipsum}% to show a \parbox in use
\moderncvstyle{casual}
\firstname{First}
\familyname{Last}
% Create our lengths
\newlength\boxsize
\newlength\boxgap
% Set them to current moderncv lengths
\setlength{\boxsize}{0.175\textwidth}% == maincolumnwidth
\setlength{\boxgap}{0.025\textwidth} % == separatorcolumnwidth
\newcommand\mycvitem[3][0.25em]{%
\strut% I prefer \strut; but it will be trumped by a
% sufficiently large value for #1 (default of 0.25em is from
% moderncv). In fact, I'd get rid of it entirely, since you use #1
% to set the space that *follows* the entry, which I find counter-intuitive
\parbox{\boxsize}{#2}%
\hspace{\boxgap}%
\parbox[t]{\dimexpr\textwidth-\boxsize-\boxgap\relax}{#3}
\par\addvspace{#1}%
}
\newcommand\mynewcvitem[3][0.25em]{%
\addvspace{#1}%
\strut% \strut can still be trumped, and we're keeping the default
% value just for fun; but now at least the space is added in
% a way that, to me, makes more sense
\parbox[t]{\boxsize}{#2}%
\hspace{\boxgap}%
\parbox[t]{\dimexpr\textwidth-\boxsize-\boxgap\relax}{#3}%
\par
}
% ... but really, I'd probably get rid of the optional argument entirely
\begin{document}
\makecvtitle
\section{Original}% <-- for comparison
\cvitem{Year}{Entry}
\cvitem{Year}{Entry}
\cvitem{Year}{Entry}
\section{Some examples}
\mycvitem[1cm]{Year}{\lipsum[2]}% <-- N.B.: #1 affects what follows
\mycvitem{2001--2013}{I am a dark knight}
\mycvitem{2001--2013}{No, I am a dark knight}
\mynewcvitem[1.5cm]{2001--2013}{I, too, am a dark knight}% <-- N.B. #1 affects what precedes
\mynewcvitem{2001--2013}{Who cares?}
\section{A New Section}% <-- Just to give a sense of the spacing
\end{document}
编辑。如果您希望“年份”框的大小具有灵活的大小,您可以执行以下操作:
% command to set \boxsize; must be a valid length
\newcommand{\setboxsize[1]{\setlength{\boxsize}{#1}}
% now we set the default \boxsize to moderncv's 0.175\textwidth,
% but allow it to be reset as an optional argument
\newcommand\revisedcvitem[3][0.175\textwidth]{%
\setlength{\boxsize}{#1}%
\strut
\parbox[t]{\boxsize}{#2}%
\hspace{\boxgap}%
\parbox[t]{\dimexpr\textwidth-\boxsize-\boxgap\relax}{#3}%
\par
}
然后像这样使用它:
\revisedcvitem[1cm]{Year}{\lipsum[2]}
\revisedcvitem{2001--2013}{I am a dark knight}
\revisedcvitem{2001--2013}{No, I am a dark knight}
\revisedcvitem[2.5cm]{2001--2013}{I, too, am a dark knight}
\revisedcvitem{2001--2013}{Who cares?}
或者您可以将其设置为一整套 \revisedcvitem,如下所示:
\boxwidth{2.5cm}% set \boxsize to 2.5cm
\revisedcvitem{Year}{\lipsum[2]}
\revisedcvitem{2001--2013}{I am a dark knight}
\revisedcvitem{2001--2013}{No, I am a dark knight}
\revisedcvitem{2001--2013}{I, too, am a dark knight}
\revisedcvitem{2001--2013}{Who cares?}