这是我的 MWE:
\documentclass[11pt,a4paper,sans,english]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman')
\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'oldstyle' and 'banking'
\moderncvcolor{blue} % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
%\nopagenumbers{} % uncomment to suppress automatic page numbering for CVs longer than one page
\usepackage[utf8]{inputenc} % if you are not using xelatex ou lualatex, replace by the encoding you are using
\usepackage[scale=0.75,a4paper]{geometry}
\usepackage{babel}
\usepackage[style=authoryear,sorting=ydnt,dashed=false,backend=bibtex]{biblatex}
\setlength{\hintscolumnwidth}{2cm}
\usepackage[most]{tcolorbox}
\definecolor{mycolor}{RGB}{222, 216, 243}
\tcbset{
frame code={}
bottom title,
box align=base,
colback=mycolor,
colframe=black,
width=\maincolumnwidth,
boxsep=4pt,
arc=0pt,outer arc=0pt,
}
\renewcommand*{\cvitem}[3][.25em]{%
\begin{tabular}{p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}}%
\raggedleft\hintstyle{#2} & {#3}%
\end{tabular}%
\par\addvspace{#1}}
\renewcommand*{\cventry}[7][.25em]{%
\cvitem[#1]{
#2
}{%
\begin{tcolorbox}[tcbox raise base]
{\bfseries#3\newline}%
\ifthenelse{\equal{#4}{}}{}{{\slshape#4, }}%
\ifthenelse{\equal{#5}{}}{}{#5\newline}%
\ifthenelse{\equal{#6}{}}{}{#6\newline}%
\end{tcolorbox}
.\strut%
\ifx&%
\else{\newline{}\begin{minipage}[t]{\linewidth}\small#7\end{minipage}}\fi}}
\begin{document}
\cventry{arg2}{arg3}{arg4}{arg5}{arg6}{arg7}
\end{document}
我想要实现的是arg2
顶部对齐(与 对齐arg3
)。 似乎p{\hintscolumnwidth}
无法\cvitem
正常工作。 有什么想法可以做到这一点吗?
谢谢。
答案1
对齐很困难,除非使用一个技巧:tcolorbox
对左列(出现 的位置)使用另一个,通过步进计数器为每个列arg2
建立一个。equal height group
cventry
equalheightgroup
我建议也使用三种样式:moderncvcommon
、moderncvbox
和itembox
,其中和moderncvcommon
都使用。这允许更改两个框的对齐等规范。moderncvbox
itembox
一些旁注:\newline
没有论点,也没有\else
\documentclass[11pt,a4paper,sans,english]{moderncv} % possible options include font size ('10pt', '11pt' and '12pt'), paper size ('a4paper', 'letterpaper', 'a5paper', 'legalpaper', 'executivepaper' and 'landscape') and font family ('sans' and 'roman')
\moderncvstyle{classic} % style options are 'casual' (default), 'classic', 'oldstyle' and 'banking'
\moderncvcolor{blue} % color options 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'
%\nopagenumbers{} % uncomment to suppress automatic page numbering for CVs longer than one page
\usepackage[utf8]{inputenc} % if you are not using xelatex ou lualatex, replace by the encoding you are using
\usepackage[scale=0.75,a4paper]{geometry}
\usepackage{babel}
\usepackage[style=authoryear,sorting=ydnt,dashed=false,backend=bibtex]{biblatex}
\setlength{\hintscolumnwidth}{2cm}
\newcounter{equalheightgroup}
\usepackage[most]{tcolorbox}
\definecolor{mycolor}{RGB}{222, 216, 243}
\tcbset{%
moderncvcommon/.style={
enhanced,
frame hidden,
sharp corners,
box align=top,
boxsep=4pt,
nobeforeafter,
equal height group=cvitem\number\value{equalheightgroup}
},
moderncvbox/.style={
moderncvcommon,
colback=mycolor,
width=\maincolumnwidth,
},
itembox/.style={%
moderncvcommon,
colback=white,
width=\hintscolumnwidth+\tabcolsep+\separatorcolumnwidth},
}
\renewcommand*{\cvitem}[3][.25em]{%
\begin{tabular}{p{\hintscolumnwidth}@{\hspace{\separatorcolumnwidth}}p{\maincolumnwidth}}%
\raggedleft\hintstyle{#2} & {#3}%
\end{tabular}%
\par\addvspace{#1}}
\renewcommand*{\cventry}[7][.25em]{%
\stepcounter{equalheightgroup}%
\cvitem[#1]{%
\begin{tcolorbox}[itembox]
#2%
\end{tcolorbox}
}{%
\begin{tcolorbox}[moderncvbox]
\textbf{#3}\newline%
\ifthenelse{\equal{#4}{}}{}{{\slshape#4, }}%
\ifthenelse{\equal{#5}{}}{}{#5\newline}%
\ifthenelse{\equal{#6}{}}{}{#6\newline}%
\end{tcolorbox}
.\strut%
\ifx&%
\else
\newline
\begin{minipage}[t]{\linewidth}\small#7\end{minipage}}\fi
}
\firstname{foo}
\lastname{bar}
\begin{document}
\cventry{arg2}{arg3}{arg4}{arg5}{arg6}{arg7}
\end{document}