8

I'm using minipage and flushleft/right in an item to achieve an item with some left aligned text and a right aligned date associated with it. However, the right alignment is problematic. The first problem is white space after lines, but if I use % then I can remove this, although it would be nice if I didn't have to litter %'s everywhere. The second problem is the last element is further right aligned. Also, if I use \break after any item, it is fully right aligned (but there is obviously an undesired new line). I discovered removing the \vspace command causes correct right alignment, but I want to reduce the vertical space.

\newcommand{\resitemwithdate}[2]{
    \vspace{-3pt}
    \item {
        \begin{minipage}[t]{.80\linewidth}
            \flushleft #1
        \end{minipage}
        \hfill
        \begin{minipage}[t]{.15\linewidth}
            \flushright #2%
        \end{minipage}%
    }%
}

\begin{itemize}
    \resitemwithdate{A}{B}
    \resitemwithdate{A}{B}%
    \resitemwithdate{A}{B}\break
    \resitemwithdate{A}{B}
\end{itemize}

Screenshot of output

5
  • 1
    \item does not have a mandatory argument and one white space is due to \resitemwithdate{
    – user31729
    Commented Feb 11, 2017 at 13:48
  • Thanks, putting a % after \resitemwithdate[2]{ has fixed it in all but the first \item there – but it still requires a % after each item. Is there any way to say 'ignore all whitespaces at the end of lines in this command' and after each item, or in an environment?
    – Nick
    Commented Feb 11, 2017 at 13:52
  • Carefully typing the definition of your command will remove all of those white spaces.
    – user31729
    Commented Feb 11, 2017 at 13:56
  • You need to add \par at the end.
    – Johannes_B
    Commented Feb 11, 2017 at 14:18
  • 2
    Completely off-topic: I hope i never see this code again in some template.
    – Johannes_B
    Commented Feb 11, 2017 at 14:19

3 Answers 3

9

\flushright etc. introduce additional vertical white space, making \vspace 'necessary', I recommend \raggedright etc. for this.

\item does not have a mandatory argument!

In addition, I recommend the enumitem package for fine control of the vertical spacings in an itemize list.

\documentclass{article}

\usepackage{enumitem}

\usepackage{showframe}% Remove this later on

\newcommand{\resitemwithdate}[2]{%
\item 
  \begin{minipage}[t]{.80\linewidth}
    \raggedright #1%
  \end{minipage}
  \hfill
  \begin{minipage}[t]{.15\linewidth}
    \raggedleft #2%
  \end{minipage}
}

\begin{document}
\begin{itemize}[itemsep=0pt]
    \resitemwithdate{A}{B}
    \resitemwithdate{A}{B}
    \resitemwithdate{A}{B}
\end{itemize}
\end{document}

enter image description here

6

And now for something completely different!

I use the listliketab package, to emulate an itemize environment, customised with enumitem, and the date-time2 package to format the date, within a tabularx environment:

\documentclass[british]{article}%
 \usepackage{enumitem, tabularx, listliketab}
 \usepackage{babel} %
 \usepackage[british]{datetime2, }%
 \usepackage{datetime2-calc, fmtcount}%
 \DTMlangsetup[en-GB]{abbr, ord=raise}
  \usepackage{lipsum}%
 \usepackage{showframe}% Remove this later on
\newlist{myitemize}{itemize}{1}
\setlist[myitemize]{wide=0pt, label=\textbullet, leftmargin=*}
\newcommand{\resitemwithdate}[2]{%
\item
  \begin{minipage}[t]{.80\linewidth}
    \raggedright #1%
  \end{minipage}
  \hfill
  \begin{minipage}[t]{.15\linewidth}
    \raggedleft #2%
  \end{minipage}
}
\let\tabitem=\textbullet

\begin{document}

\storestyleof{myitemize}
\begin{listliketab}
  \begin{tabularx}{\linewidth}{@{}L >{\hsize=1.6\hsize}X >{\hsize=0.42\hsize\raggedleft\arraybackslash}X@{}}
    \tabitem & \lipsum[11] & \Today \\
 \tabitem & \lipsum[3] & \Today%
    \end{tabularx}
\end{listliketab}

\end{document} 

enter image description here

5

As exercise:

\documentclass{article}
\newcommand{\resitemwithdate}[2]
{
    \setlength\itemsep{0pt}%
    \item   \begin{minipage}[t]{.80\linewidth}\raggedright
                #1
            \end{minipage}
            \hfill
            \begin{minipage}[t]{.15\linewidth}\raggedleft
                #2 
            \end{minipage}% 
}

\usepackage{showframe}                     % remove in real document
\renewcommand*\ShowFrameColor{\color{red}} % remove in real document

\begin{document}
\begin{itemize}
    \resitemwithdate{A}{B}
    \resitemwithdate{A}{B}
    \resitemwithdate{A}{B}\break
    \resitemwithdate{A}{B}
\end{itemize}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .