创建嵌套列表

创建嵌套列表

我正在尝试创建以下列表

在此处输入图片描述

我编写的模板如下所示。但是缩进不正确。

 \documentclass[12pt]{article}
 % Packages used in template.
 \usepackage{enumitem}
 \usepackage{changepage}
 \usepackage{etoolbox}

 % Set left, right, top, and bottom margins of the paper.
 \usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in]{geometry}
 \voffset = 0.15in
 \headsep = 31pt
 \topmargin = -48pt

 % Create new environments for listings
 \setlist[enumerate]{wide, align=left, topsep = 0in, parsep = 0.24in, partopsep = 0in, itemsep = 0in, labelindent = 0in, labelsep = 0.36in}
 \newenvironment{FirstList}[1][]{ \begingroup \let \olditem \item
     \renewcommand \item {\olditem
     \ifnum\value{enumi} > 9
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 99
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 999
     \setlength\hskip{-0.14in}
     \fi
     }
     \begin{enumerate}[#1] } {\end{enumerate} \endgroup}

 \newenvironment{SecondList}{ \begin{adjustwidth}{0.48in}{0in}
     \begin{enumerate}}{ \end{enumerate} \end{adjustwidth}}

 \begin{document}
     \begin{FirstList}

        \item This template is made for A4 page size. I will try to extend this point into more than two lines.

        \item In this template,

        \begin{SecondList}
            \item Left margin is $\mathrm{1.5}$ in.

            \item Right margin is $\mathrm{0.7}$ in.

        \end{SecondList}

        \item This is another enumerated point.

         \begin{SecondList}
            \item This is another enumerated point.

            \item This is another enumerated point.
        \end{SecondList}

         \item This is another enumerated point.

    \end{FirstList}
 \end{document}

答案1

SecondList稍微编辑了一下您的环境。第一个列表是您指定的输出内容。后面是hrulefill您在 MWI 中给出的输出内容。希望对您有所帮助。

\documentclass[12pt]{article}
 % Packages used in template.
 \usepackage{enumitem}
 \usepackage{changepage}
 \usepackage{etoolbox}

 % Set left, right, top, and bottom margins of the paper.
 \usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in]{geometry}
 \voffset = 0.15in
 \headsep = 31pt
 \topmargin = -48pt

 % Create new environments for listings
 \setlist[enumerate]{wide, align=left, topsep = 0in, parsep = 0.24in, partopsep = 0in, itemsep = 0in, labelindent = 0in, labelsep = 0.36in}

 \newenvironment{FirstList}[1][]{ \begingroup \let \olditem \item
     \renewcommand \item {\olditem
     \ifnum\value{enumi} > 9
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 99
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 999
     \setlength\hskip{-0.14in}
     \fi
     }
     \begin{enumerate}[#1] } {\end{enumerate} \endgroup}

 \newenvironment{SecondList}[1][]{
    \begin{adjustwidth}{0.48in}{0in}
        \begin{enumerate}
            [#1]}{ % I added [#1], it worked.
        \end{enumerate}
    \end{adjustwidth}
    }

\begin{document}
    % This code will produce output like the image you provided.
    \begin{FirstList}
        \item This template is made for A4 page size. I will try to extend this point into more than two lines.

        \item In this template,
    \end{FirstList}
    \vspace{0.24in}
    \begin{SecondList}[label=(\alph*)]
        \item Left margin is $\mathrm{1.5}$ in.

        \item Right margin is $\mathrm{0.7}$ in.

        \begin{SecondList}[label=(\roman*)]
            \item Another nested item.

            \item Yet another nested item.

        \end{SecondList}

    \end{SecondList}
    \vspace{0.24in}
    \begin{FirstList}[label=(\theenumi)]
        \setcounter{enumi}{2}
        \item A theenumi item.

        \item Yet another theenumi item.
    \end{FirstList}

    \hrulefill
    \newline

    % This is the setting for the listing you provided.
    \begin{FirstList}
        \item This template is made for A4 page size. I will try to extend this point into more than two lines.

        \item In this template,

    \end{FirstList}

    \vspace{0.24in}

    \begin{SecondList}[label=(\alph*)]
        \item Left margin is $\mathrm{1.5}$ in.

        \item Right margin is $\mathrm{0.7}$ in.

    \end{SecondList}

    \vspace{0.24in}

    \begin{FirstList}[label=(\theenumi)]
        \setcounter{enumi}{2}
        \item This is another enumerated point.
    \end{FirstList}

    \vspace{0.24in}

    \begin{SecondList}[label=(\alph*)]
        \item This is another enumerated point.

        \item This is another enumerated point.
    \end{SecondList}

    \vspace{0.24in}     

    \begin{FirstList}[label=(\theenumi)]
        \setcounter{enumi}{3}
        \item This is another enumerated point.

    \end{FirstList}

\end{document}

编辑:对于多重嵌套

\documentclass[12pt]{article}
 % Packages used in template.
 \usepackage{enumitem}
 \usepackage{changepage}
 \usepackage{etoolbox}

 \newcommand{\adj}[1]{\begin{adjustwidth}{0.48in}{0in} #1 \end{adjustwidth}}

 % Set left, right, top, and bottom margins of the paper.
 \usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in]{geometry}
 \voffset = 0.15in
 \headsep = 31pt
 \topmargin = -48pt

 % Create new environments for listings
 \setlist[enumerate]{wide, align=left, topsep = 0in, parsep = 0.24in, partopsep = 0in, itemsep = 0in, labelindent = 0in, labelsep = 0.36in}

 \newenvironment{FirstList}[1][]{ \begingroup \let \olditem \item
     \renewcommand \item {\olditem
     \ifnum\value{enumi} > 9
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 99
     \setlength\hskip{-0.14in}
     \fi
     \ifnum\value{enumi} > 999
     \setlength\hskip{-0.14in}
     \fi
     }
     \begin{enumerate}[#1] } {\end{enumerate} \vspace{0.24in} \endgroup}

 \newenvironment{SecondList}[1][]{
    \begin{adjustwidth}{0.48in}{0in}
        \begin{enumerate}[label=#1]
            }{ % I added [#1], it worked.
        \end{enumerate}
    \end{adjustwidth} \vspace{0.24in}
    }

\begin{document}
    % This code will produce output like the image you provided.
    \begin{FirstList}
        \item This is the first item in the first `FirstList' environment.
        \item This is the second item in the first `FirstList' environment. To start a secondary list, termination of this `FirstList' is necessary.
    \end{FirstList}
    \begin{SecondList}[(\alph*)]
            \item This is the first item of first nested list using `SecondList' environment.
            \item The second one
    \end{SecondList}
    \adj{
        \begin{SecondList}[(\alph*)]
            \item I've created an \texttt{\textbackslash adj} new command that will indent it properly.
            \item It'll also keep the second indentation proper.
        \end{SecondList}
    }
    \adj{
        \adj{
            \begin{SecondList}[(\alph*)]
                \item For multiple indentations use \texttt{\textbackslash adj} multiple times.
            \end{SecondList}
        }
    }
    \adj{
        \adj{
            \adj{
                \begin{SecondList}[(\alph*)]
                    \item For multiple indentations use \texttt{\textbackslash adj} multiple times.
                \end{SecondList}
            }
        }
    }
    \adj{
        \adj{
            \adj{
                \adj{
                    \begin{SecondList}[(\alph*)]
                        \item For multiple indentations use \texttt{\textbackslash adj} multiple times.
                    \end{SecondList}
                }
            }
        }
    }
\end{document}

答案2

这能达到目的吗?

\documentclass[12pt]{article}
\usepackage{enumitem}
\usepackage[a4paper, left = 1.5in, right = 0.70in, top = 0.5in, bottom = 2.2in]{geometry}
\voffset = 0.15in
\headsep = 31pt
\topmargin = -48pt
\newcounter{myenumi}
\renewcommand{\themyenumi}{%
\arabic{myenumi}.}
\newenvironment{myenumerate}{%
% stuff for beginning of environment goes here
\setlength{\parindent}{0pt}% don't indent paragraphs
\setcounter{myenumi}{0}% restart numbering
\bigskip% skip a line
\newcommand{\myitem}{% new definition of item
\par% start a new line
\refstepcounter{myenumi}% advance counter
\makebox[2em][l]{\themyenumi}% print counter to width of 3em, aligned to left
}% end of definition of item
}{% at end of environment
\par% start new paragraph
%\bigskip% skip a line
\noindent% don't indent new paragraph
\ignorespacesafterend% ignore spaces after environment
}

\begin{document}
\begin{myenumerate}
    \myitem Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
    \myitem Text
    \renewcommand{\labelenumi}{(\alph{enumi})}
    \begin{enumerate}
        \itemindent=1em
        \itemsep=0pt
        \item Text
        \item Text
        \renewcommand{\labelenumii}{(\roman{enumi})}
        \begin{enumerate}
            \itemindent=0.6em
            \itemsep=0pt
            \item Text
            \item Text
        \end{enumerate}
    \end{enumerate}
    \renewcommand{\themyenumi}{(\arabic{myenumi})}
    \myitem Text
    \myitem Text
\end{myenumerate}
\end{document}

答案3

抱歉,据我所知,你应该直接阅读enumitem 的文档仔细检查。表 1 显示了缩进等操作所需的所有参数。然后使用\alph\roman\arabic

定义一个\newlist。一旦你理解了它,这将非常有用。

这是我快速编写的一个例子。你可以根据自己的需要进行调整。

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{enumitem}

\begin{document}

\newlist{mylist}{enumerate}{3}
    \setlist[mylist,1]{label={\arabic*.}, resume, leftmargin=*, labelindent=\parindent, rightmargin=1.8\parindent, parsep={\parskip}, itemsep=0.3ex}
    \setlist[mylist,2]{label={(\alph*)}, leftmargin=2.2\parindent, rightmargin=1.8\parindent, itemsep=0.3ex, itemindent=10ex}
    \setlist[mylist,3]{label=\textbf{(\roman*)}, leftmargin=5\parindent, rightmargin=0\parindent, itemsep=0.3ex, itemindent=-5ex}

\begin{mylist}
\item one
\item two
\begin{mylist}
\item level two with a long text and a certain indent in the first and another in the following lines (also i played around with rightmargins just to show what is possible)
\begin{mylist}
\item level three with a long text and a certain indent in the first and another in the following lines (also i played around with rightmargins just to show what is possible)
\item second one here on level three
\end{mylist}
\item second one on level two
\end{mylist}
\end{mylist}
\begin{mylist}[labelsep=20ex]
\item three
\end{mylist}

\end{document}

因此,我认为这比其他解决方案更整洁。如果您的列表中缺少某些关键功能,并且无法轻松实现enumitem,请对我的答案发表评论。

相关内容