3

I'd like to create a ragged right inlist list, where each item is separated by either a bullet or a line break.

For example: I'd like the following

\usepackage{ragged2e}
\begin{minipage}[t]{0.31\textwidth}
  \begin{flushleft}
    \begin{mylist}
      \item Apple 
      \item Berry
      \item Rocky~Road 
      \item Cream
      \item Jello
      \item Fish 
    \end{mylist}
  \end{flushleft}

To yield this: enter image description here

So more specifically, each item should be separated by a bullet until we hit the end of a line, in which case a line break should be used instead.

Right now, I have to manually format the list like so:

\begin{flushleft}
  Apple \textbullet{} Berry\\
  Rocky~Road \textbullet{} Cream\\
  Jello \textbullet{} Fish 
\end{flushleft}

This latter way of doing it is extremely painful as any update to the list involves manually reformatting the whole list.

Paralist comes close to providing the functionality I need, but it precedes each item with a bullet, whereas I need to separate each item with either a bullet or a linebreak.

Thank you for your time!

Anonymous
  • 133

1 Answers1

4

enter image description here

\documentclass{article}

\newenvironment{mylist}{\def\item{\ifhmode\cleaders\hbox to 1.9em{\hss\textbullet\hss}\hskip2em\fi}}{}
\begin{document}


\begin{minipage}[t]{0.31\textwidth}
  \begin{flushleft}
    \begin{mylist}
      \item Apple 
      \item Berry
      \item Rocky~Road 
      \item Cream
      \item Jello
      \item Fish 
    \end{mylist}
  \end{flushleft}
\end{minipage}
\hfill\vrule\hfill
\begin{minipage}[t]{0.61\textwidth}
  \begin{flushleft}
    \begin{mylist}
      \item Apple 
      \item Berry
      \item Rocky~Road 
      \item Cream
      \item Jello
      \item Fish 
    \end{mylist}
  \end{flushleft}
\end{minipage}

\end{document}
David Carlisle
  • 757,742
  • 1
    Remember to add some mortar to your bricks of code. – Werner May 31 '17 at 21:57
  • Thank you so much! I'm sorry, but I'm still very new to LaTeX so I was wondering if I could trouble you for a brief explanation of your if statement? – Anonymous May 31 '17 at 22:11
  • 1
    @Anonymous the if just checks you are in horizontal mode and does nothing if in vertical mode (so does nothing before the first item at the start of the paragraph) – David Carlisle May 31 '17 at 22:16
  • Thank you so much@DavidCarlisle! I'm afraid that I'm so new that I don't quite understand the "then" clause of the if statement either =( Would you be able to briefly explain that clause as well and/or tell me where I could read up about boxes and glues so that I could understand? – Anonymous May 31 '17 at 22:45
  • 1
    @Anonymous I'm sure we have an answer explaining leaders, I'll see if I can find a link – David Carlisle May 31 '17 at 22:51
  • 1
    @Anonymous this one shows leaders being used in a similar way in the vertical direction https://tex.stackexchange.com/questions/186328/section-break-that-displays-content-iff-it-occurs-in-middle-of-a-page/186330#186330 – David Carlisle May 31 '17 at 22:56
  • 1
    @Anonymous also https://tex.stackexchange.com/questions/253291/equivalent-leaders-construction/253303#253303 – David Carlisle May 31 '17 at 23:13
  • Okay thank you! So if I'm reading this correctly: \hskip2em: Insert 2em worth of fixed space. which is then modified by \cleaders which says "fill the 2em space with as many copies as possible of 1.9em boxes, centering the copies when there's extra space." \hbox to 1.9em{\hss\textbullet\hss} creates an 1.9em box and fills it with a text bullet that's centered in the middle such that if it's too small, space is added but if it's too big, the overflow is even on both sides. – Anonymous May 31 '17 at 23:44
  • 1
    @David Carlisle could you please explain the coding you have used \ifhmode and \cleaders? – Biki Teron May 31 '17 at 23:45
  • 1
    @Anonymous yes in general for leaders although of course in this case since the glue is fixed size you always get exactly one box, but the leaders is then discarded at a line break just as normal space is. – David Carlisle Jun 01 '17 at 06:55
  • Thank you @DavidCarlisle! That really helps me understand the "then" clause. Is the enclosing "if" statement to prevent errors from trying to use a leader when in vertical mode? – Anonymous Jun 01 '17 at 18:18
  • 1
    @Anonymous you wouldn't get an error you'd just get a bullet before the first item, which wasn't required here. – David Carlisle Jun 01 '17 at 18:25
  • The bullet isn’t really centered between two items; it’s always positioned a little bit to the right. What can be done here? – Sebastian Simon Jul 09 '19 at 07:44
  • 1
    @SebastianSimon oh \unskip just before the \cleaders. – David Carlisle Jul 09 '19 at 07:55