2

The following code

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

gives the output below: enter image description here which is not the desired one I want. The output that I exactly want should be there are no words appear in the same line with the itemize tags. For example, "Let $\varepsilon > 0$..." should be right below the "Initialization Step" (with some indent is also desirable). Is there any easy way to fulfill this? Thank you very much.

4
  • 1
    \item[Initialization Step]\mbox{}\\
    – egreg
    Jan 28, 2016 at 22:55
  • OK, this works perfectly for the first item. However, when I tried the same trick after Main Step, it produces a large vertical space, how to deal with that?
    – Zhanxiong
    Jan 28, 2016 at 22:59
  • 1
    In the second one you don't add \\
    – egreg
    Jan 28, 2016 at 23:04
  • This really should be done using the nextline style in enumitem, but there seems to be a problem using this with nested lists...see Problem using enumitem's nextline style with nested lists
    – user30471
    Jan 29, 2016 at 22:56

1 Answer 1

1

The best way to do this is using a description environment together with tweaks from the enumitem package. Unfortunately, there is an issue using nested lists with enumitem's style=nextline but Bernard has given a fix in Problem using enumitem's nextline style with nested lists.

Another benefit of using enumitem is that you can control the formatting of the labels.

Here is the output from the MWE below:

enter image description here

Here is the code:

\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}
2
  • @Andrew: If I may suggest, I would add to the nested enumerate one of the options [wide=0pt] or [labelindent= 0pt, align= left, labelsep=0.4em, leftmargin=*], so the numbering starts at the left margin of the description environment.
    – Bernard
    Jan 30, 2016 at 10:28
  • @Bernard Is there a way of adding these dynamically? The whole point of using the \ifInDescription flag was that I wanted nested environments to work without any (obvious) modifications.
    – user30471
    Jan 30, 2016 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .