下面的代码
\begin{description}
\item[\emph{Initialization Step}]
Let $\varepsilon > 0$ be a termination tolerance. Choose an initial point $\theta^{(1)}$. Let $X^{(1)} = (0, 0, 0, 0, \ldots, 0, \theta^{(1)T})^T$, $j = 1$ and go to the Main Step.
\item[\emph{Main Step}]
\begin{enumerate}
\item For given $\theta^{(j)}$, solve the linear program \eqref{LP} to get $\hat{\xi}^{(j + 1)} = \hat{\xi}$.
\item Substitute $\hat{\xi}^{(j + 1)}$ into \eqref{mainproblem}, solve the resulting nonlinear program to get $\hat{\theta}^{(j + 1)}$. Form $X^{(j + 1)} = (\hat{\xi}^{(j + 1)T}, \hat{\theta}^{(j + 1)T})^T$. If $\|X^{(j + 1)} - X^{(j)}\| < \varepsilon$, stop; otherwise, replace $j$ by $j + 1$, and go to step 1.
\end{enumerate}
\end{description}
给出以下输出: 这不是我想要的。我真正想要的输出应该是没有单词出现在 itemize 标签的同一行中。例如,“让 $\varepsilon > 0$...” 应该位于“初始化步骤”的正下方(最好有一些缩进)。有什么简单的方法可以实现这一点吗?非常感谢。
答案1
最好的方法是使用description
环境以及来自枚举项包。不幸的是,使用嵌套列表时存在一个问题枚举项的style=nextline
Bernard 已经给出了解决方案使用 enumitem 的 nextline 样式与嵌套列表时出现问题。
使用的另一个好处枚举项您可以控制标签的格式。
以下是 MWE 的输出:
以下是代码:
\documentclass{article}
\usepackage{enumitem}
\newif\ifInDescription\InDescriptionfalse%
\newcommand\NestingFix{% if inside Description force line break
\ifInDescription%
\leavevmode\vspace*{-\dimexpr2\topsep+\baselineskip\relax}%
\fi%
}
\newlist{algorithm}{description}{1}
\setlist[algorithm]{style=nextline,% each label on its own line
before=\InDescriptiontrue,% starting Description
after=\InDescriptionfalse,% leaving Description
font=\itshape\bfseries% set font for labels
}
\setlist{before=\NestingFix}% apply nesting fix to all list environments
\begin{document}
\begin{algorithm}
\item[Initialization Step]
Let $\varepsilon > 0$ be a termination tolerance. Choose an
initial point $\theta^{(1)}$. Let $X^{(1)} = (0, 0, 0, 0,
\ldots, 0, \theta^{(1)T})^T$, $j = 1$ and go to the Main
Step.
\item[Main Step]
\begin{enumerate}
\item For given $\theta^{(j)}$, solve the linear program
\eqref{LP} to get $\hat{\xi}^{(j + 1)} = \hat{\xi}$.
\item Substitute $\hat{\xi}^{(j + 1)}$ into
\eqref{mainproblem}, solve the resulting nonlinear program to
get $\hat{\theta}^{(j + 1)}$. Form $X^{(j + 1)} =
(\hat{\xi}^{(j + 1)T}, \hat{\theta}^{(j + 1)T})^T$. If
$\|X^{(j + 1)} - X^{(j)}\| < \varepsilon$, stop; otherwise,
replace $j$ by $j + 1$, and go to step 1.
\end{enumerate}
\end{algorithm}
\end{document}