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{\,}}, ...}
Notes:
- I attempted to use the solutions in What is the meaning of \fussy, \sloppy, \emergencystretch, \tolerance, \hbadness?, but was not able to get them to work either.
- It seems that I have asked a similar question a long time ago Why is text being placed beyond the specified line width?, but here I am using
\sloppyand\RaggedRightbut that still is not sufficient.
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:
References
- How to insert a non-stretching but line-breaking thin space?.
- What is the meaning of \fussy, \sloppy, \emergencystretch, \tolerance, \hbadness?
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, 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 04 '18 at 23:55