我正在尝试创建嵌套枚举列表的模板。第一个列表的标签与页面的左边距对齐(使用环境 FirstList)。然后,后续嵌套列表会缩进一些空格(使用环境 SecondList)。为了缩进嵌套列表,我使用了 adjustwidth,但是,这会导致多出一对括号。请参见下图。
\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-如何移除多余的支架?
问题 2——是否可以创建一个可以做到这一点的单一环境?
答案1
我留给你关于边距的细节,从你的问题中看不太清楚。特别是,添加所需的值rightmargin
。
你能和应该为此使用单一环境并且不要超载enumerate
。
我改变了 的一些值geometry
,首先是因为\voffset
永远不应该用于定位文本块,也不应该修改\topmargin
。
\documentclass[12pt]{article}
% Packages used in template.
\usepackage{enumitem}
\usepackage{changepage}
\usepackage{etoolbox}
% Set left, right, top, and bottom margins of the paper.
\usepackage[
showframe,
a4paper,
left = 1.5in,
right = 0.70in,
top = 1in,
bottom = 1.05in,
headsep=31pt,
]{geometry}
%\voffset = 0.15in %%%% <---- NO
%\headsep = 31pt %%%% <---- NO
%\topmargin = -48pt %%%% <---- NO
% Create new environments for listings
\newlist{mylist}{enumerate}{3}
\setlist[mylist]{
wide,
align=left,
topsep = 0in,
parsep = 0.24in,
partopsep = 0in,
itemsep = 0in,
labelsep = 0in,
itemindent=0.5in,
labelindent = -0.5in,
labelwidth=0.5in,
}
\setlist[mylist,1]{leftmargin=0in,label=\arabic*.}
\setlist[mylist,2]{leftmargin=0.5in,label=(\alph*)}
\setlist[mylist,3]{leftmargin=1in,label=(\roman*)}
\begin{document}
\begin{mylist}
\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{mylist}
\item Left margin is $\mathrm{1.5}$ in.
\item Right margin is $\mathrm{0.7}$ in.
\end{mylist}
\item This is another enumerated point.
\begin{mylist}
\item This is another enumerated point.
\item This is another enumerated point.
\end{mylist}
\item This is another enumerated point.
\end{mylist}
\end{document}
答案2
将环境更改SecondList
为
\newenvironment{SecondList}
{\begin{enumerate}[leftmargin=1in, rightmargin=0in, labelindent=*]}
{\end{enumerate}}
作品。
- 对应
leftmargin=1in, rightmargin=0in
于您的原始值\begin{adjustwidth}{0.48in}{0in}
。这里我使用较大的值,leftmargin
因为您使用了较大的值labelsep = 0.36in
。 - 强制
labelindent=*
重新计算。
完整示例:
\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, showframe]{geometry}
% 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{enumerate}[leftmargin=1in, rightmargin=0in, labelindent=*]}
{\end{enumerate}}
\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}
顺便一提,
- 不建议设置
\voffset
为非零值,完全可以避免。使用geometry
选项并仅使用它们就足够了。 \setlist
例如,可以为不同级别的列表设置不同的样式\setlist[enumerate, 2]{...}
。因此您的FistList
和SecondList
环境也是可以避免的。
答案3
正如 muzimuzhi 在这篇好文章的结尾所说,枚举项包提供了更好的工具来做这种事情。您可以使用它\setlist[enumerate,1]{...}
来设置环境第一级所需的参数enumerate
,然后\setlist[enumerate,2]{...}
设置第二级等。因此,按照 muzimuzhi 的建议,您可以使用以下命令设置enumerate
环境:
\setlist[enumerate,1]{
wide,
align=left,
topsep = 0in,
parsep = 0.24in,
partopsep = 0in,
itemsep = 0in,
labelindent = 0in,
labelsep = 0.36in,
}
\setlist[enumerate,2]{
leftmargin=1in,
rightmargin=0in,
labelindent=*
}
这仍然保留了您的自定义\item
命令。与其每次FirstList
使用环境时都定义它,不如将此代码移到序言中,如下所示:
\let\olditem\item
\newcommand\MyItem {\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
}
要enumerate
使用它,您可以将其添加before=\let\item\MyItem
到\setlist
命令中。实现这一点后,您可以删除FirstList
和SecondList
环境,而只需使用enumerate
(或者,您也可以用定义新的列表环境\newlist
),这样您的 MWE 就变成了
\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, showframe]{geometry}
\let\olditem\item
\newcommand\MyItem {\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
}
% Create new environments for listings
\setlist[enumerate,1]{
wide,
align=left,
topsep = 0in,
parsep = 0.24in,
partopsep = 0in,
itemsep = 0in,
labelindent = 0in,
labelsep = 0.36in,
before=\let\item\MyItem
}
\setlist[enumerate,2]{
leftmargin=1in,
rightmargin=0in,
labelindent=*
}
\begin{document}
\begin{enumerate}
\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{enumerate}
\item Left margin is $\mathrm{1.5}$ in.
\item Right margin is $\mathrm{0.7}$ in.
\end{enumerate}
\item This is another enumerated point.
\begin{enumerate}
\item This is another enumerated point.
\item This is another enumerated point.
\end{enumerate}
\item This is another enumerated point.
\end{enumerate}
\end{document}
输出结果和 muzimuzhi 的回答一模一样:
编辑
据我所知,这在嵌套中确实可以正常工作?例如,\documentclass[12pt]{article} % 模板中使用的包。\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, showframe]{geometry}
\let\olditem\item
\newcommand\MyItem {\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
}
% Create new environments for listings
\setlist[enumerate,1]{
wide,
align=left,
topsep = 0in,
parsep = 0.24in,
partopsep = 0in,
itemsep = 0in,
labelindent = 0in,
labelsep = 0.36in,
before=\let\item\MyItem
}
\setlist[enumerate,2]{
leftmargin=1in,
rightmargin=0in,
labelindent=*
}
\begin{document}
\begin{enumerate}
\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{enumerate}
\item This template is made for A4 page size. I will try to extend
this point into more than two lines.
\item Left margin is $\mathrm{1.5}$ in.
\item Right margin is $\mathrm{0.7}$ in.
\end{enumerate}
\item This is another enumerated point.
\begin{enumerate}
\item This is another enumerated point.
\item This template is made for A4 page size. I will try to extend
this point into more than two lines.
\item This is another enumerated point.
\end{enumerate}
\item This is another enumerated point.
\end{enumerate}
\end{document}
生成: