1

This is a follow-up to How to insert a non-stretching but line-breaking thin space?, but in reference to an inline list. The MWE below attempts to use each of the solutions mentioned there, but the best I can using:

\sloppy\RaggedRight
%\ttfamily

is shown in the image below. Ultimately, I want to use \ttfamily in this list (but that is another problem entirely and should probably be a separate question), thus the use of \normalfont in:

\setlist[MyList*]{..., itemjoin={\normalfont,\BreakableSpace{\,}}, ...}

enter image description here

Notes:

Question:

What options do I have to force the text to stay within the specified area?

Slightly Better Results:

It seems that if I move the \sloppy\RaggedRight to be before I call \TypesetMyList as in:

{\sloppy\RaggedRight\TypesetMyList{Title}{MyList*}}

the results are better but still has some additional leading space at the beginning of lines:

enter image description here

References

Code:

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{microtype}

\usepackage[showframe, paperwidth=5cm]{geometry}

\newlist{MyList*}{enumerate*}{1}
\setlist[MyList*]{label={}, itemsep=0pt, itemjoin={\normalfont,\BreakableSpace{\,}}, after={.}}


%% https://tex.stackexchange.com/questions/78914/
%%         how-to-insert-a-non-stretching-but-line-breaking-thin-space

\newcommand*{\addthinspace}{\hskip0.16667em\relax}% lockstep

\newcommand\bigspace{\kern 0.1em}% <-- Changed amount here as I don't want large space
\newcommand\breakingspaceJfbuA{\allowbreak\bigspace\allowbreak}% jfbu's 1st solution
\newcommand\breakingspaceJfbuB{\allowbreak\bigspace}%            jfbu's 2nd solution

\newcommand{\breakingspaceEgregA}[1]{#1\hspace{0pt}}%      egreg's 1st solution
\newcommand{\breakingspaceEgregB}[1]{{\let\kern\hskip#1}}% egreg's 2nd solution
\newcommand{\badbreakingspace}[1]{\penalty 0 #1}%          egreg's 3rd solution


%% Select which breakable space we want to try. First uncommented one here gets used:
\providecommand*{\BreakableSpace}[1]{\addthinspace}

\providecommand*{\BreakableSpace}[1]{\breakingspaceJfbuA}
\providecommand*{\BreakableSpace}[1]{\breakingspaceJfbuB}

\providecommand*{\BreakableSpace}[1]{\breakingspaceEgregA{#1}}
\providecommand*{\BreakableSpace}[1]{\breakingspaceEgregB{#1}}
\providecommand*{\BreakableSpace}[1]{\badbreakingspace{#1}}


\newcommand*{\TypesetMyList}[2]{%
\smallskip%
\par\noindent{\bfseries#1:}~%
\begingroup
    \sloppy\RaggedRight
    %\ttfamily
    \begin{#2}
        \item First Item
        \item Second item in list
        \item Third item
        \item Fourth item in list
        \item Fifth item
        \item Sixth item in list
        \item Seventh item
        \item Eighth item in list
    \end{#2}%
\endgroup\smallskip\par%
}%

\begin{document}
Some text before the start of the list.
\TypesetMyList{Title}{MyList*}
Some text after the end of the list.
\end{document}
  • ttfamily would change things quite a bit as the inter-word space is then not stretchy by default, so if that's what you want, possibly the initial exampe should use that. – David Carlisle Dec 4 '18 at 22:25
  • @DavidCarlisle: Yeah I normally would have included \ttfamily, but as it seemed to be another can of worms as per How to automatically hyphenate within \texttt?, I decided not too. As egreg's solution already seems to work for that case I won't post a new question (unless some other issue comes up). – Peter Grill Dec 4 '18 at 23:55
1

You're forgetting to set afterlabel that, by default, is ~ (non breaking space).

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{microtype}

\usepackage[showframe, paperwidth=5cm]{geometry}

\newlist{MyList*}{enumerate*}{1}
\setlist[MyList*]{
  label={},
  itemsep=0pt,
  itemjoin={\normalfont,},
  afterlabel={\hspace{0.16667em}},
  after={.}
}

\begin{document}
Some text before the start of the list.

\noindent\textbf{Title:}~%
\begingroup\sloppy\RaggedRight
\begin{MyList*}
  \ttfamily
  \item First Item
  \item Second item in list
  \item Third item
  \item Fourth item in list
  \item Fifth item
  \item Sixth item in list
  \item Seventh item
  \item Eighth item in list
\end{MyList*}
\par\endgroup

\end{document}

enter image description here

You can also use before to set up other features. If you add \csname @@par\endcsname to after, \RaggedRight and \sloppy will be honored. If you want to change the font for the items, but preserve normal font commas, use \textnormal{,}.

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{microtype}

\usepackage[showframe, paperwidth=5cm]{geometry}

\newlist{MyList*}{enumerate*}{1}
\setlist[MyList*]{
  label={},
  itemsep=0pt,
  itemjoin={\textnormal{,}},
  afterlabel={\hspace{0.16667em}},
  after={.\csname @@par\endcsname},
  before={\sloppy\RaggedRight\ttfamily},
}

\begin{document}
Some text before the start of the list.

\noindent\textbf{Title:}~%
\begin{MyList*}
  \item First Item
  \item Second item in list
  \item Third item
  \item Fourth item in list
  \item Fifth item
  \item Sixth item in list
  \item Seventh item
  \item Eighth item in list
\end{MyList*}

\end{document}

enter image description here

1

\raggedright handles the list, although the text before is ~2pt over

\documentclass{article}
\usepackage[inline]{enumitem}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{microtype}

\usepackage[showframe, paperwidth=5cm]{geometry}

\newlist{MyList*}{enumerate*}{1}
\setlist[MyList*]{label={}, itemsep=0pt, itemjoin={\normalfont,\BreakableSpace{\,}}, after={.}}


%% https://tex.stackexchange.com/questions/78914/
%%         how-to-insert-a-non-stretching-but-line-breaking-thin-space

\newcommand*{\addthinspace}{\hskip0.16667em\relax}% lockstep

\newcommand\bigspace{\kern 0.1em}% <-- Changed amount here as I don't want large space
\newcommand\breakingspaceJfbuA{\allowbreak\bigspace\allowbreak}% jfbu's 1st solution
\newcommand\breakingspaceJfbuB{\allowbreak\bigspace}%            jfbu's 2nd solution

\newcommand{\breakingspaceEgregA}[1]{#1\hspace{0pt}}%      egreg's 1st solution
\newcommand{\breakingspaceEgregB}[1]{{\let\kern\hskip#1}}% egreg's 2nd solution
\newcommand{\badbreakingspace}[1]{\penalty 0 #1}%          egreg's 3rd solution


%% Select which breakable space we want to try. First uncommented one here gets used:
\providecommand*{\BreakableSpace}[1]{\addthinspace}

\providecommand*{\BreakableSpace}[1]{\breakingspaceJfbuA}
\providecommand*{\BreakableSpace}[1]{\breakingspaceJfbuB}

\providecommand*{\BreakableSpace}[1]{\breakingspaceEgregA{#1}}
\providecommand*{\BreakableSpace}[1]{\breakingspaceEgregB{#1}}
\providecommand*{\BreakableSpace}[1]{\badbreakingspace{#1}}


\newcommand*{\TypesetMyList}[2]{%
\smallskip%
\par\noindent{\bfseries#1:}~%
\begingroup
    \raggedright
    %\ttfamily
    \begin{#2}
        \item First Item
        \item Second item in list
        \item Third item
        \item Fourth item in list
        \item Fifth item
        \item Sixth item in list
        \item Seventh item
        \item Eighth item in list
    \end{#2}%
\par\endgroup\smallskip\par%
}%

\begin{document}
Some text before the start of the list.
\TypesetMyList{Title}{MyList*}
Some text after the end of the list.
\end{document}

enter image description here

  • although you want to change \, to an hskip (eg the \addthinspace so it is discarded at start of line. – David Carlisle Dec 4 '18 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.