内联列表:如何插入不拉伸但换行的细空格?

内联列表:如何插入不拉伸但换行的细空格?

这是如何插入不拉伸但换行的细空格?,但参考的是内联列表。下面的 MWE 尝试使用每个那里提到的解决方案,但我能使用的最好的解决方案是:

\sloppy\RaggedRight
%\ttfamily

如下图所示。最终,我想\ttfamily在这个列表中使用(但那完全是另一个问题,可能应该是一个单独的问题),因此使用\normalfontin:

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

在此处输入图片描述

笔记:

问题:

我有什么选项可以强制文本停留在指定区域内?

稍好一些的结果:

似乎如果我\sloppy\RaggedRight移动\TypesetMyList这样称呼:

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

结果更好,但在行首仍然有一些额外的前导空格:

在此处输入图片描述

参考

代码:

\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}

答案1

您忘记设置afterlabel默认值了~(不间断空格)。

\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}

在此处输入图片描述

您还可以使用before来设置其他功能。如果您将 添加\csname @@par\endcsnameafter\RaggedRight\sloppy将被接受。如果您想更改项目的字体,但保留正常字体逗号,请使用\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}

在此处输入图片描述

答案2

\raggedright处理列表,尽管之前的文本超出了约 2pt

\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}

在此处输入图片描述

相关内容