[Tex/LaTex] Left-align the date for all cvitems

horizontal alignmentmacrosmoderncv

All contents (mostly dates) of the first argument of \cvitem should left-align in Austria – as explained to me in the career center. I want to redefine the command \cvitem (like in Can I redefine a command to contain itself?).

\let\oldcvitem\cvitem
\renewcommand*{\cvitem}[3][]{\oldcvitem}

My 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}

Best Answer

A MWE for moderncv requires adding the choice of \moderncvstyle, \firstname and \familyname.

The easiest way to tweak \cvitem is to copy its definition from one of the moderncvstyle files:

\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}

I have added some bars to the tabular environment, to make it clear how each \cvitem is typeset.

enter image description here

From here you can either customise the tabular environment or it entries. I'm not sure I understood exactly what your requirements are, but you can left-align the year by removing \raggedleft from the tabular entries.

enter image description here

Edit:

In the version above, the year column is clearly too wide (0.15\textwidth). The width of the column may be controlled using \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}

enter image description here

Related Question