遗憾的是,我无法重新创建 MWE,因为我正在处理一个相当复杂的模板。我无法理解 LaTeX 如何决定换行,我在 Google 上搜索过,但找不到明确的答案。这是我正在使用的代码:
\begin{itemize}
% [...]
\item A TOSCA requirement definition within a node type definition was encoded with the term
\texttt{requirement(}$RName$\texttt{, }$RCap$\texttt{, }$RNType$\texttt{, }$RRel$\texttt{, occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$ is an atom for the name of the
requirement, $RCap$ is an atom for the required capability, $RNType$ is an atom for the type of nodes admitted
as a target (including subtypes), $RRel$ is an atom representing the relationship underlying the requirement,
and $ROccLB$ and $ROccUB$ are respectively lower and upper bound for the number of occurrences of the
requirement, $ROccUB$ possibly being the atom \texttt{unbounded};
% [...]
\end{itemize}
如果我在代码中第一次出现 之后添加一个换行符(文字换行符,而不是\\
,后跟缩进) ,则该行在 之后会正确断开,如下所示:$RRel$
$ROccLB$
我知道 LaTeX 的工作方式很神秘,但我想了解这种行为。
平均能量损失
\documentclass{article}
\addtolength\textwidth{45pt}
\begin{document}
\begin{itemize}
\item A TOSCA requirement definition within a node type definition was
encoded with the term \texttt{requirement(}$RName$\texttt{,
}$RCap$\texttt{, }$RNType$\texttt{, }$RRel$\texttt{,
occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
is an atom for the name of the requirement, $RCap$ is an atom for
the required capability, $RNType$ is an atom for the type of nodes
admitted as a target (including subtypes), $RRel$ is an atom
representing the relationship underlying the requirement, and
$ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
number of occurrences of the requirement, $ROccUB$ possibly being
the atom \texttt{unbounded};
\item A TOSCA requirement definition within a node type definition was
encoded with the term \texttt{requirement(}$RName$\texttt{,
}$RCap$\texttt{, }$RNType$\texttt{, }$RRel$ \texttt{,
occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
is an atom for the name of the requirement, $RCap$ is an atom for
the required capability, $RNType$ is an atom for the type of nodes
admitted as a target (including subtypes), $RRel$ is an atom
representing the relationship underlying the requirement, and
$ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
number of occurrences of the requirement, $ROccUB$ possibly being
the atom \texttt{unbounded};
\end{itemize}
\end{document}
答案1
我不会使用数学模式。相反,我会使用文本模式,无论是函数名称(例如\texttt
)还是变量名称(例如\textit
)。并且,如果需要,只需插入\-
任意连字符即可。
\documentclass{article} % or some other suitable document class
\newcommand\fn[1]{\texttt{#1}} % function name
\newcommand\vn[1]{\textit{#1}} % variable name
\begin{document}
\begin{itemize}
\item A TOSCA requirement definition within a node type definition
was encoded with the term \fn{requirement}[\vn{RName}, \vn{RCap},
\vn{RNType}, \vn{RRel}, \fn{occur\-rences}(\hspace{0pt}\vn{ROccLB},
\vn{ROccUB})], where \vn{RName} is an atom for the name of the
requirement, \vn{RCap} is an atom for the required capability,
\vn{RNType} is an atom for the type of nodes admitted as a target
(including subtypes), \vn{RRel} is an atom representing the relationship
underlying the requirement, and \vn{ROccLB} and \vn{ROccUB} are
respectively lower and upper bound for the number of occurrences
of the requirement, \vn{ROccUB} possibly being the atom
\fn{unbounded}; \dots
\end{itemize}
\end{document}
答案2
只需将空格移出范围即可\texttt
:
\documentclass{article}
\addtolength\textwidth{45pt}
\begin{document}
\begin{itemize}
\item A TOSCA requirement definition within a node type definition was
encoded with the term \texttt{requirement(}$RName$\texttt{,}
$RCap$\texttt{,} $RNType$\texttt{,} $RRel$\texttt{,}
\texttt{occurrences(}$ROccLB$\texttt{,} $ROccUB$\texttt{))}, where $RName$
is an atom for the name of the requirement, $RCap$ is an atom for
the required capability, $RNType$ is an atom for the type of nodes
admitted as a target (including subtypes), $RRel$ is an atom
representing the relationship underlying the requirement, and
$ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
number of occurrences of the requirement, $ROccUB$ possibly being
the atom \texttt{unbounded};
\end{itemize}
\end{document}
假设\texttt
空格是固定宽度的,而原始编码只为包含固定宽度材料和数学的行分配了两个可伸缩空格,这远远不足以实现合理的对齐。观察发现,当空格从 的范围中移除后,段落中的行会以不同的方式换行\texttt
。
附录
关于名称编码的其他答案是正确的。现在编码为数学的名称实际上应该编码为显式斜体。如果它们通常出现在数学环境中,则应将其编码为 (例如)$\mathit{RName}$
而不是$RName$
。它们看起来会好得多,因为它们是单词,而不是相互乘以的变量字符串,这是数学中对字母的通常处理。
答案3
如果您使用\mathit
,文本会更加压缩(且可读),并允许数学中逗号后的空格具有一定的灵活性,那么它(几乎)可以放在一行而不会中断,请参阅下面的第三项。
\documentclass{article}
\addtolength\textwidth{45pt}
\begin{document}
\begin{itemize}
\item A TOSCA requirement definition within a node type definition was
encoded with the term \texttt{requirement(}$RName$\texttt{,
}$RCap$\texttt{, }$RNType$\texttt{, }$RRel$\texttt{,
occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
is an atom for the name of the requirement, $RCap$ is an atom for
the required capability, $RNType$ is an atom for the type of nodes
admitted as a target (including subtypes), $RRel$ is an atom
representing the relationship underlying the requirement, and
$ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
number of occurrences of the requirement, $ROccUB$ possibly being
the atom \texttt{unbounded};
\item A TOSCA requirement definition within a node type definition was
encoded with the term \texttt{requirement(}$RName$\texttt{,
}$RCap$\texttt{, }$RNType$\texttt{, }$RRel$ \texttt{,
occurrences(}$ROccLB$\texttt{, }$ROccUB$\texttt{))}, where $RName$
is an atom for the name of the requirement, $RCap$ is an atom for
the required capability, $RNType$ is an atom for the type of nodes
admitted as a target (including subtypes), $RRel$ is an atom
representing the relationship underlying the requirement, and
$ROccLB$ and $ROccUB$ are respectively lower and upper bound for the
number of occurrences of the requirement, $ROccUB$ possibly being
the atom \texttt{unbounded};
\item \sloppy \thinmuskip=3mu plus 2mu minus 1.5mu A TOSCA requirement definition within a node type definition was
encoded with the term $\mathtt{requirement}(\mathit{RName},
\mathit{RCap}, \mathit{RNType}, \mathit{RRel},
\mathtt{occurrences}(\mathit{ROccLB}, \mathit{ROccUB}))$, where $\mathit{RName}$
is an atom for the name of the requirement, $\mathit{RCap}$ is an atom for
the required capability, $\mathit{RNType}$ is an atom for the type of nodes
admitted as a target (including subtypes), $\mathit{RRel}$ is an atom
representing the relationship underlying the requirement, and
$\mathit{ROccLB}$ and $\mathit{ROccUB}$ are respectively lower and upper bound for the
number of occurrences of the requirement, $\mathit{ROccUB}$ possibly being
the atom \texttt{unbounded};
\end{itemize}
\end{document}