7

I have created a new inline list style with enumitem that has no bullets and separates each item with a middle dot:

\documentclass{article}

\newcommand{\middot}{~\textperiodcentered~}

\usepackage[inline]{enumitem}
\newlist{skills}{itemize*}{1}
\setlist[skills]{label={}, afterlabel={}, itemjoin=\middot}

\begin{document}
  \begin{skills}
    \item Something
    \item Another thing
    \item Foobar
    \item etc.
  \end{skills}
\end{document}

This works great, but when the list of items overruns the line width, then it's possible that LaTeX will split on my \middot separator. Which looks a bit like this (imagine my ASCII asterisks are \textperiodcentered characters!):

|   Something * Another thing *   |
|   Foobar * etc.                 |

I can get around this by judiciously choosing the order and the text in each of the \items to avoid this. What would be nice, however, is that in this circumstance, LaTeX replaces the hanging middle dot with a line feed automatically (stretching the character spacing of that line, appropriately), without any fussy manual intervention. So the above might look like this (again, use your imagination!):

|   Something  *  Another thing   |
|   Foobar * etc.                 |

(The case where the item text itself gets wrapped to the next line is fine. It's just the hanging middle dots that don't look nice.)

How could one achieve this?


EDIT I've finally been able to reproduce an example of this problem, including using the \discretionary advice from @DavidCarlisle:

\documentclass[a4paper]{article}

\newcommand{\middot}{~\textperiodcentered~}

\usepackage[inline]{enumitem}
\newlist{skills}{itemize*}{1}
\setlist[skills]{label={}, afterlabel={}, itemjoin=\discretionary{}{}{\hbox{\middot}}}

\setlength{\parindent}{0pt}

\begin{document}
  \begin{skills}
    \item This is
    \item a list of things
    \item that should hopefully
    \item break a line at
    \item some point
    \item if I just keep adding
    \item things
  \end{skills}
\end{document}

...which produces this output:

output demonstrating hanging separator

Note that hanging separator at the end of the first line. While the discretionary does make the problem less frequent, I presume this happens because (La)TeX doesn't want to hyphenate at this point, so just falls back to a straight line break.

10
  • it would be easier to test possible answers if you edited the example to be an example of the problem. Commented Apr 5, 2019 at 17:19
  • The reason I posted this is because I was expecting the ~ non-breaking space to do the work for me. In my question, I've been trying to set the \textwidth value to force this behaviour, but it seems like LaTeX is actually respecting the non-breaking space. However, outside my minimal example, I am still witnessing this behaviour...but that could be due to any number of things :/ It may simply be because of \textwidth is an unreasonable thing to use to force the behaviour. Commented Apr 8, 2019 at 10:18
  • You could ask a question about dropping the separator at a linebreak (which you could do with a discretionary) without needing to make an example where the line breaks before the *. If you made an example that had a linebreak at all.... Commented Apr 8, 2019 at 10:21
  • 1
    for the middot you would need \discretionary{}{}{\hbox{$middot$}} as you can't have a mathchar in a disc node but can have an hbox that can contain anything Commented Apr 15, 2019 at 16:13
  • 1
    I think I could solve your problem if you used mode=unboxed for your list. However, I am struggling to find an MWE for which it exists at all with this option. Do you observe any unwanted line breaks with this option? Do you have any reason not to use it?
    – schtandard
    Commented May 8, 2019 at 20:34

1 Answer 1

2
+50

This is really a comment, expanding on schtandard's remark. Here is an example that show that the code works with mode=unboxed:

Sample output

\documentclass[a4paper]{article}

\newcommand{\middot}{~\textperiodcentered~}

\usepackage[inline]{enumitem}
\newlist{skills}{itemize*}{1}
\setlist[skills]{label={}, afterlabel={}, mode=unboxed,
itemjoin=\discretionary{}{}{\hbox{\middot}}}

\setlength{\parindent}{0pt}

\begin{document}

\showoutput
  \begin{skills}
    \item This is
    \item a list of things
    \item that should hopefully
    \item break a line at
    \item some point~x
    \item if I just keep adding
    \item things
  \end{skills}
\end{document}

You get the same output in the following boxed example, where the line manually extended so there is no need for any \rightskip:

\documentclass[a4paper]{article}

\newcommand{\middot}{~\textperiodcentered~}

\usepackage[inline]{enumitem}
\newlist{skills}{itemize*}{1}
\setlist[skills]{label={}, afterlabel={},
itemjoin=\discretionary{}{}{\hbox{\middot}}}

\setlength{\parindent}{0pt}

\begin{document}

\showoutput
  \begin{skills}
    \item This is
    \item a list of things
    \item that should hopefully
    \item break a line at
    \item some point~x\kern6pt
    \item if I just keep adding
    \item things
  \end{skills}
\end{document}

You must log in to answer this question.

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