3

This is my 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&#7&%
        \else{\newline{}\begin{minipage}[t]{\linewidth}\small#7\end{minipage}}\fi}}
\begin{document}
\cventry{arg2}{arg3}{arg4}{arg5}{arg6}{arg7}
\end{document}

See the result here: enter image description here

What I would like to achieve is to have arg2 top aligned (in line with arg3). It seems that p{\hintscolumnwidth} in \cvitem does not work properly. Any idea on how to do this?

Thanks.

1
  • maybe what you really need is the colortbl package? It lets you lay out tables as usually be also paint individual cells, columns, or rows with background colour. – Michael Palmer Feb 2 '18 at 23:32
5

The alignment is difficult, unless doing a trick: Use another tcolorbox for the left column (where arg2) appears, establishing an equal height group for each cventry by stepping the counter equalheightgroup.

I suggest to use three styles as well: moderncvcommon, moderncvbox and itembox, where moderncvcommon is used by both moderncvbox and itembox. This allows to change the specifications of alignment etc for both boxes.

Some sidenotes: \newline does not have an argument, nor does \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&#7&%
      \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}

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.