50 enumitem 宏包 itemindent=\parindent 的设置在abstract环境内、外的效果不同?

发布于 2025-09-01 22:56:31

配置

Win11; TeXLive2024; VSCode.

问题背景

想使用 enumitem 宏包下 \setlist 的设置来实现:列表环境各条目呈现为段落(各条目首行缩进,其余行顶格)。

目前可得如下方案能初步实现目标:

\setlist{
align=left, %标签在盒子内居左对齐
leftmargin=0pt, %条目左边距为0
itemindent=\dimexpr\parindent+\labelwidth+\labelsep\relax, %条目内缩进距离,除掉标签宽度、标签内容间距后刚好等于段落缩进距离
}

但实践中发现,摘要环境以外区域的enumerate环境均能呈现上述效果,而以内区域则不行。由此内外效果不一致。

逐步剖析后基本确定根源为:值含\parindentitemindent键在摘要环境内外的效果不一致。

问题描述

引入 enumitem 宏包并设置如下:

\setlist{
itemindent=\parindent,
}

编译后发现:摘要环境enumerate环境效果与摘要环境外的不一致。

在这里想寻求:

  • 出现该现象的主要原因;
  • 如何使摘要环境内的enumerate环境效果与摘要环境的一致。

做过的尝试:

  • \parindent改为固定值(以5em为例):摘要环境内外的enumerate环境效果均一致;
  • 在摘要环境内、外分别用\the\parindent来查看值是否一致:均为 15.0pt

MWE

\documentclass{article}

\usepackage{showframe}
\usepackage{lipsum}

\usepackage{abstract}
\setlength{\absleftindent}{0pt} %取消左边距
\setlength{\absrightindent}{0pt} %取消右边距
\renewcommand{\abstracttextfont}{\normalsize} %确保摘要环境内外字号一致

\usepackage{enumitem}
\setlist{
itemindent=\parindent,
}


\begin{document}

\begin{abstract}

\lipsum[2]

\begin{enumerate}
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\end{enumerate}

\end{abstract}

\lipsum[2]

\begin{enumerate}
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\end{enumerate}

\end{document}

image.png

查看更多

关注者
0
被浏览
197
2 个回答
Sagittarius Rover
这家伙很懒,什么也没写!

maybe related to \quotation:

如果先暂时不看abstract宏包

\setlength{\absleftindent}{0pt} %取消左边距
\setlength{\absrightindent}{0pt} %取消右边距
\renewcommand{\abstracttextfont}{\normalsize} %确保摘要环境内外字号一致

的设置...

% line 366~408 article.cls
\if@titlepage
    ....
\else
  \newenvironment{abstract}{%
      \if@twocolumn
        \section*{\abstractname}%
      \else
        \small
        \begin{center}%
          {\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
        \end{center}%
        \quotation
      \fi}
      {\if@twocolumn\else\endquotation\fi}
\fi
...
\newenvironment{quotation}
               {\list{}{\listparindent 1.5em%
                        \itemindent    \listparindent
                        \rightmargin   \leftmargin
                        \parsep        \z@ \@plus\p@}%
                \item\relax}
               {\endlist}

其中在abstarct中的首行缩进名为\listparindent 1.5em.可见下例。

\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
\parindent=0em

\makeatletter
  \renewenvironment{abstract}{%
  \if@twocolumn
    \section*{\abstractname}%
  \else
    \small
    \begin{center}%
      {\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
    \end{center}%
    \quotation
  \fi}
  {\if@twocolumn\else\endquotation\fi}

\renewenvironment{quotation}
   {\list{}{%
            \listparindent 1.5em% %<-important here
            \itemindent    \listparindent
            \rightmargin   \leftmargin
            \parsep        \z@ \@plus\p@}%
    \item\relax}
   {\endlist}

\makeatother

\begin{document}

\lipsum[2]

\begin{abstract}

\lipsum[2]

\end{abstract}

\lipsum[2]

\end{document}

image.png


哇...根源貌似找到了:abstract环境内又嵌套了quotation环境,而quotation环境内主动将itemindent的值设为了\listparindent

对的。

那请问怎么少改动的“使内的与外的一致”呢,从局部优先的特征来看只能重定义整个quotation环境了吗...

我感觉重定义quotation也并不太好,这可能影响正文中正常使用quotation环境。

「怎么少改动的“使内的与外的一致”呢?」按我理解的需求是:

  • abstract内的首行间距与\parindent一致
  • 不影响正文中quotation环境的正常使用

我感觉把\quotation复制一份使用\parindent的版本\myquotation专门用于abstarct也许会更好(?)例如这样:

\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}

\usepackage{etoolbox}
\makeatletter
\NewCommandCopy{\myquotation}{\quotation}
\renewcommand\myquotation{%
    \list{}{%\listparindent 1.5em%
            \itemindent    \parindent %\listparindent
            \rightmargin   \leftmargin
            \parsep        \z@ \@plus\p@}%
        \item\relax
}
\patchcmd{\abstract}{\quotation}{\myquotation}{}{}
\makeatother

\parindent=0em

\begin{document}

\begin{quotation}
    \lipsum[2][1-5]
\end{quotation}

\lipsum[2][1-5]

\begin{abstract}

\lipsum[2][1-5]

\begin{quotation}
    \lipsum[2][1-5]
\end{quotation}

\end{abstract}

\lipsum[2]

\begin{quotation}
    \lipsum[2][1-5]
\end{quotation}

\end{document}

image.png

此时对于正文段落的间距\parindent似乎是一致了,但对于enumerate似乎仍有问题...

\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
\usepackage{abstract}
\setlength{\absleftindent}{0pt}
\setlength{\absrightindent}{0pt}
\renewcommand{\abstracttextfont}{\normalsize}
\usepackage{etoolbox}
\makeatletter
\NewCommandCopy{\myquotation}{\quotation}
\renewcommand\myquotation{%
    \list{}{%\listparindent 1.5em%
            \itemindent    \parindent%\listparindent
            \rightmargin   \leftmargin
            \parsep        \z@ \@plus\p@}%
        \item\relax
}
\patchcmd{\abstract}{\quotation}{\myquotation}{}{}
\makeatother

\parindent=4em

\begin{document}

\lipsum[2][1-5]

\begin{abstract}

\lipsum[2][1-5]

\begin{enumerate}
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\end{enumerate}

\end{abstract}

\lipsum[2]

\begin{enumerate}
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text. 
\end{enumerate}

\end{document}

image.png

沉默...


把评论区中的测试代码搬到我们的目标「希望abstract环境」和「正文环境」保持一致,注意quotation环境中实际上就是一个\list,既然我们想要和正文一致,不妨直接(非常暴力地)把\myquotation置为空,这样似乎就不会受到:

\listparindent 1.5em%
\itemindent    \listparindent
\rightmargin   \leftmargin
\parsep        \z@ \@plus\p@

的影响了...(因为原先abstract内部就借用了quotation内部也借用了\list,所以在abstract内部用enumerate实际上是"list in list"...)

这样的话,也不需要abstract宏包调整字号了,直接从底层自定义想要的abstract环境...(嗯我也不知道好不好...)

\documentclass{article}
\usepackage{showframe}
\usepackage{lipsum}
%% 不用 abstract 宏包,自力更生吧...
\usepackage{etoolbox}
\patchcmd{\abstract}{\small}{}{}{}
\patchcmd{\abstract}{\quotation}{}{}{}
\patchcmd{\endabstract}{\endquotation}{}{}{}

\newcommand\txt{This is some txt txt txt txt txt txt. }
\newcommand\mytxt{\txt\txt\txt\txt\txt\txt}
\newcommand*\printvalue[1]{\texttt{\string #1} : \the #1}

\parindent=2em % 为了适应「10.」的两位数缩进稍微调大了...
\usepackage{enumitem}
\setlist{
    align=left,
    leftmargin=0pt,
    itemindent=\parindent,
    labelindent=0pt,
    labelwidth=!,
}

\begin{document}

\makeatletter
\texttt{\meaning\abstract}

\texttt{\meaning\endabstract}
\makeatother

\lipsum[2][1-5]

\begin{abstract}

\lipsum[2][1-5]

\begin{enumerate}[start=8]
\item \printvalue\leftmargin
\item \printvalue\itemindent
\item \printvalue\labelsep
\item \printvalue\labelwidth
\item \printvalue\labelindent
\item \mytxt
\end{enumerate}

\end{abstract}

\lipsum[2]

\begin{enumerate}[start=8]
\item \printvalue\leftmargin
\item \printvalue\itemindent
\item \printvalue\labelsep
\item \printvalue\labelwidth
\item \printvalue\labelindent
\item \mytxt 
\end{enumerate}

\end{document}

image.png

shadow
shadow 2天前
这个人懒得不得了,竟然啥也没写

查看 abstract 宏包的环境定义,可能和内部调用 center 环境有关

\if@titlepage \renewenvironment{abstract}{%
  \titlepage \null\vfil \@beginparpenalty\@lowpenalty
  \begin{center}%
    \bfseries \abstractname \@endparpenalty\@M
\end{center}}%
{\par\vfil\null\endtitlepage}
\else \renewenvironment{abstract}{%
  \if@twocolumn
  \section*{\abstractname}%
  \else \small
  \begin{center}%
    {\bfseries \abstractname\vspace{-.5em}\vspace{\z@}}%
  \end{center}%
\quotation \fi} {\if@twocolumn\else\endquotation\fi}
\fi

将 MWE 中的 abstract 环境改为 center 环境

\documentclass{article}

\usepackage{showframe}
\usepackage{lipsum}

\usepackage{abstract}
\setlength{\absleftindent}{0pt} %取消左边距
\setlength{\absrightindent}{0pt} %取消右边距
\renewcommand{\abstracttextfont}{\normalsize} %确保摘要环境内外字号一致

\usepackage{enumitem}
\setlist{
  itemindent=\parindent,
}

\begin{document}

\begin{center}

  \lipsum[2]

  \begin{enumerate}
    \item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
    \item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
  \end{enumerate}

\end{center}

\lipsum[2]

\begin{enumerate}
  \item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
  \item this is text. this is text. this is text. this is text. this is text. this is text. this is text. this is text.
\end{enumerate}

\end{document}

image.png
效果和以上展示的一致,初步判断就是 center 所致。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览