多级列表错误

多级列表错误

我已经创建了一个具有很多级别的列表,并且使用了 TeX SE 和 ShareLaTeX 的资源来实现这一点,但是当我尝试编译它时,我在代码中的多个点收到错误“缺少数字,视为零”,我无法弄清楚原因,因为将资源与我的代码进行比较表明它应该可以工作。

我的代码如下:

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{float}
\usepackage{framed}
\usepackage[hang,flushmargin]{footmisc}
\usepackage{enumitem}

\setlistdepth{6}
\newlist{myEnumerate}{enumerate}{7}
\setlist[myEnumerate, 1]{label=(\arabic)}
\setlist[myEnumerate, 2]{label=(\arabic)}
\setlist[myEnumerate, 3]{label=(\arabic)}
\setlist[myEnumerate, 4]{label=(\arabic)}
\setlist[myEnumerate, 5]{label=(\arabic)}
\setlist[myEnumerate, 6]{label=(\arabic)}
\setlist[myEnumerate, 7]{label=(\arabic)}

\begin{document}
\begin{proof}
Here is an algorithm for $\overline{PATH}$. Let $m$ be the number of nodes in $G$. 

$M= \text{``On input } \langle G,s,t \rangle$
\begin{myEnumerate}
\item Let $c_0=1$
\item For $i=0$ to $m-1$:
\begin{myEnumerate}
\item Let $c_{i+1}=1$
\item For each node $v \neq s$ in $G$:
\begin{myEnumerate}
\item Let $d=0$
\item For each node $u$ in $G$:
\begin{myEnumerate}
\item Non-deterministically either perform or skip these steps:
\begin{myEnumerate}
\item Non-deterministically follow a path of length at most $i$ from $s$ and \textit{reject} if it doesn't end at $u$
\item Increment $d$
\item If $(u,v)$ is an edge of $G$, increment $c_{i+1}$ and go to Stage 5 with the next $v$
\item If $d \neq c_i$, then \textit{reject}
\item Let $d=0$
\item For each node $u$ in $G$:
\begin{myEnumerate}
\item Non-deterministically either perform or skip these steps:
\begin{myEnumerate}
\item Non-deterministically follow a path of length at most $m$ from $s$ and \textit{reject} if it doesn't end at $u$
\item If $u=t$ then \textit{reject}
\item Increment $d$
\item If $d \neq c_m$, then \textit{reject}
\item Otherwise, \textit{accept}
\end{myEnumerate}
\end{myEnumerate}
\end{myEnumerate}
\end{myEnumerate}
\end{myEnumerate}
\end{myEnumerate}
\end{myEnumerate}
\end{proof}
\end{document}

我想要的最终文档如下所示: 在此处输入图片描述

答案1

您可以只使用单个枚举并使用缩进。此解决方案使用\parboxes,因此您不能将\item(或\ibox) 拆分到页面边界。

\documentclass{article}

\newlength{\IndentLevel}
\setlength{\IndentLevel}{0pt}
\newenvironment{myindent}{\advance\IndentLevel by 1em}{}
\newcommand{\ibox}[1]{\item\hspace{\IndentLevel}\parbox[t]{\dimexpr\linewidth-\IndentLevel}{#1}}

\begin{document}

\begin{enumerate}
\ibox{Let $c_0=1$}
\ibox{For $i=0$ to $m-1$:}
\begin{myindent}
\ibox{Let $c_{i+1}=1$}
\ibox{For each node $v \neq s$ in $G$:}
\begin{myindent}
\ibox{Let $d=0$}
\ibox{For each node $u$ in $G$:}
\begin{myindent}
\ibox{Non-deterministically either perform or skip these steps:}
\begin{myindent}
\ibox{Non-deterministically follow a path of length at most $i$ from $s$ and \textit{reject} if it doesn't end at $u$}
\ibox{Increment $d$}
\ibox{If $(u,v)$ is an edge of $G$, increment $c_{i+1}$ and go to Stage 5 with the next $v$}
\ibox{If $d \neq c_i$, then \textit{reject}}
\ibox{Let $d=0$}
\ibox{For each node $u$ in $G$:}
\begin{myindent}
\ibox{Non-deterministically either perform or skip these steps:}
\begin{myindent}
\ibox{Non-deterministically follow a path of length at most $m$ from $s$ and \textit{reject} if it doesn't end at $u$}
\ibox{If $u=t$ then \textit{reject}}
\ibox{Increment $d$}
\ibox{If $d \neq c_m$, then \textit{reject}}
\ibox{Otherwise, \textit{accept}}
\end{myindent}
\end{myindent}
\end{myindent}
\end{myindent}
\end{myindent}
\end{myindent}
\end{enumerate}

\end{document}

相关内容