这是如何插入不拉伸但换行的细空格?,但参考的是内联列表。下面的 MWE 尝试使用每个那里提到的解决方案,但我能使用的最好的解决方案是:
\sloppy\RaggedRight
%\ttfamily
如下图所示。最终,我想\ttfamily
在这个列表中使用(但那完全是另一个问题,可能应该是一个单独的问题),因此使用\normalfont
in:
\setlist[MyList*]{..., itemjoin={\normalfont,\BreakableSpace{\,}}, ...}
笔记:
- 我尝试使用以下解决方案\fussy、\sloppy、\emergencystretch、\tolerance、\hbadness 是什么意思?,但也无法让它们工作。
- 我好像很久以前问过类似的问题为什么文本超出了指定的线宽?,但这里我使用
\sloppy
和,\RaggedRight
但这仍然不够。
问题:
我有什么选项可以强制文本停留在指定区域内?
稍好一些的结果:
似乎如果我\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\endcsname
到after
,\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}