我是 Latex 的新手,我正在使用 moderncv 中的一个函数,\cvitemwithcomment
它需要三个输入并打印三个文本。在我的例子中,我插入的是:
\documentclass{moderncv}
\moderncvstyle{casual}
\moderncvcolor{blue}
\begin{document}
\makecvtitle
\section{Languages}
\cvitemwithcomment{Language1}{Mother tongue}{}
\cvitemwithcomment{Language2}{Some text}{This text is located on the right}
\cvitemwithcomment{Language3}{Some longer text}{This text is located on the right and it is longer}
\end{document}
我得到的是:
---------- Languages
Language1| Mother tongue
Language2| Some text This text is located on the right
Language3| Some longer text This text is located on the right and it is longer
我想做的是:
---------- Languages
Language1| Mother tongue
Language2| Some text This text is located begins at here
Language3| Some longer text This text begins in the same position even if it is longer
即让所有“第三文本”从我指定的特定水平坐标开始。我已经尝试过了\flushright
。在这种情况下,我的代码变成:
\documentclass{moderncv}
\moderncvstyle{casual}
\moderncvcolor{blue}
\begin{document}
\makecvtitle
\section{Languages}
\cvitemwithcomment{Language1}{Mother tongue}{}
\cvitemwithcomment{Language2}{Some text}{\begin{flushleft}This text begins on the left\end{flushleft}}
\cvitemwithcomment{Language2}{Some longer text}{\begin{flushleft}This text begins on the left and it is longer\end{flushleft}}
\end{document}
但它不起作用,因为如果第二段文本的长度不同,我得到的是:
---------- Languages
Language1| Mother tongue
Language2| Some text This text begins on the left
Language3| Some longer text This text begins on the left and it is longer
那么我可以使用什么呢?
答案1
您给出的 MWE 几乎很好,只\name{Joe}{Doe}
缺少一个命令,编译后不会出现错误消息。我在以下 MWE 中添加了它。
对于您来说,最好创建一个自己的命令,例如\mycvitemwithcomment
或\mybcvitemwithcomment
。
在第一个版本中,我只是在添加的代码中修复了第二列的长度3cm
(参见<=========
)。请参阅以下代码部分(在最后一行我将其更改\raggedleft
为\raggedright
):
\newcommand*{\mycvitemwithcomment}[4][.25em]{%
\savebox{\cvitemwithcommentbox}{{#3}}%
\setlength{\cvitemwithcommentskilllength}{3cm}% <=====================
\setlength{\cvitemwithcommentcommentlength}{\maincolumnwidth-\separatorcolumnwidth-\cvitemwithcommentskilllength}%
\cvitem[#1]{#2}{%
\begin{minipage}[t]{\cvitemwithcommentskilllength}\usebox{\cvitemwithcommentbox}\end{minipage}%
\hfill% fill of \separatorcolumnwidth
\begin{minipage}[t]{\cvitemwithcommentcommentlength}\raggedright\small\itshape#4\end{minipage}}}
我在“语言 2”部分展示了它的用法。
如果您需要此新命令来为第二列指定不同的长度,您可以通过添加新参数(编号 5)将上面的代码更改为以下内容。但随后您必须在每次调用该命令时添加所需的长度\mybcvitemwithcomment
:
\newcommand*{\mybcvitemwithcomment}[5][.25em]{% <==========================
\savebox{\cvitemwithcommentbox}{{#3}}%
\setlength{\cvitemwithcommentskilllength}{#5}% <=========================
\setlength{\cvitemwithcommentcommentlength}{\maincolumnwidth-\separatorcolumnwidth-\cvitemwithcommentskilllength}%
\cvitem[#1]{#2}{%
\begin{minipage}[t]{\cvitemwithcommentskilllength}\usebox{\cvitemwithcommentbox}\end{minipage}%
\hfill% fill of \separatorcolumnwidth
\begin{minipage}[t]{\cvitemwithcommentcommentlength}\raggedright\small\itshape#4\end{minipage}}}
\makeatother
然后你必须使用命令\mybcvitemwithcomment{Language1}{Mother tongue}{}{5cm}
作为示例。
我在“语言 3”部分展示了它的用法。
现在需要完整的 MWE(\makeatletter
和\makeatother
,因为插入的代码使用了@
):
\documentclass{moderncv}
\moderncvstyle{casual} % head 2, body, foot 1
\moderncvcolor{blue}
\makeatletter
\@initializebox{\cvitemwithcommentbox}
\@initializelength{\cvitemwithcommentskilllength}
\@initializelength{\cvitemwithcommentcommentlength}
\newcommand*{\mycvitemwithcomment}[4][.25em]{%
\savebox{\cvitemwithcommentbox}{{#3}}%
\setlength{\cvitemwithcommentskilllength}{3cm}% <=====================
\setlength{\cvitemwithcommentcommentlength}{\maincolumnwidth-\separatorcolumnwidth-\cvitemwithcommentskilllength}%
\cvitem[#1]{#2}{%
\begin{minipage}[t]{\cvitemwithcommentskilllength}\usebox{\cvitemwithcommentbox}\end{minipage}%
\hfill% fill of \separatorcolumnwidth
\begin{minipage}[t]{\cvitemwithcommentcommentlength}\raggedright\small\itshape#4\end{minipage}}}
\newcommand*{\mybcvitemwithcomment}[5][.25em]{% <==========================
\savebox{\cvitemwithcommentbox}{{#3}}%
\setlength{\cvitemwithcommentskilllength}{#5}% <=========================
\setlength{\cvitemwithcommentcommentlength}{\maincolumnwidth-\separatorcolumnwidth-\cvitemwithcommentskilllength}%
\cvitem[#1]{#2}{%
\begin{minipage}[t]{\cvitemwithcommentskilllength}\usebox{\cvitemwithcommentbox}\end{minipage}%
\hfill% fill of \separatorcolumnwidth
\begin{minipage}[t]{\cvitemwithcommentcommentlength}\raggedright\small\itshape#4\end{minipage}}}
\makeatother
\name{Joe}{Doe} % <=====================================================
\begin{document}
\makecvtitle
\section{Languages}
\cvitemwithcomment{Language1}{Mother tongue}{}
\cvitemwithcomment{Language2}{Some text}{This text is located on the right}
\cvitemwithcomment{Language3}{Some longer text}{This text is located on the right and it is longer}
\section{Languages 2}
\mycvitemwithcomment{Language1}{Mother tongue}{}
\mycvitemwithcomment{Language2}{Some text}{This text is located on the right}
\mycvitemwithcomment{Language3}{Some longer text}{This text is located on the right and it is longer}
\section{Languages 3}
\mybcvitemwithcomment{Language1}{Mother tongue}{}{5cm}
\mybcvitemwithcomment{Language2}{Some text}{This text is located on the right}{5cm}
\mybcvitemwithcomment{Language3}{Some longer text}{This text is located on the right and it is longer}{5cm}
\end{document}
结果:
只需选择最适合您需求的版本...