# Left-align the date for all cvitems

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}

• @jon: I thought the first argument #1 is by default the optional argument!? I am aware that '\cvitem' by default takes two arguments and an optional one. But it did not solve my problem. – strpeter Oct 29 '13 at 12:50
• OK, I looked into it. The problem is that each CV item sets its own tabular, which kind of reminds me of bad HTML. I'd be inclined to skip the whole thing and write a new command using \parbox.... – jon Oct 29 '13 at 14:08
• That would be brilliant if you could write your idea more explicit, as I do not exactly know how you would implement this command by using '\parbox'. Is it really so robust in the sense of arrangement and alignment? – strpeter Oct 29 '13 at 15:09

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

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

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.

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

\begin{document}

\makecvtitle
\cvitem{Year}{Entry}

\end{document}


First, I would like to point out that @Pedro's answer works just fine as long as you remove the \raggedleft from the re-definition (so +1). However, I find the way \addvspace used in moderncv rather unintuitive, so if I were to mimic what the class does with \parbox-es, I'd do it a little differently. Example:

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

\newcommand\mynewcvitem[3][0.25em]{%
\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}


Edit. If you want instead to have a flexible size for the size of the 'year' box, what you could do is the following:

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


Then use it like so:

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


Or you can set it for a whole suite of \revisedcvitem's like so:

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

• On the first catch, it looks fine. But my doubt was confirmed on the closer view: The contents "Year" and "Entry" (in second section) are not vertically aligned (position) anymore in contrast to the original (first section). \addvspace is nice but I don't need it for this purpose. The optional argument should change the width for the "year" box. – strpeter Oct 29 '13 at 22:02
• @strpeter -- That's because I forgot a [t] in the first \parbox. I think a flexible 'width' that has to be controlled by the the optional argument would be very annoying to use: if you have ten items, you'd need to write it each time; but there is a way to fix that. – jon Oct 30 '13 at 0:18