![如何在`enumerate`环境中新的`quotation`环境前后产生合适的空格?](https://linux22.com/image/460480/%E5%A6%82%E4%BD%95%E5%9C%A8%60enumerate%60%E7%8E%AF%E5%A2%83%E4%B8%AD%E6%96%B0%E7%9A%84%60quotation%60%E7%8E%AF%E5%A2%83%E5%89%8D%E5%90%8E%E4%BA%A7%E7%94%9F%E5%90%88%E9%80%82%E7%9A%84%E7%A9%BA%E6%A0%BC%EF%BC%9F.png)
首先是一个 MWS,其输出如下。
\documentclass{article}
\usepackage{lipsum,indentfirst}
\setlength{\parindent}{2em}
\setlength{\parskip}{0.3\baselineskip plus 0.2ex minus 0.1ex}
%%%enumerate and so on%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{enumitem}
%space for items--------------------------------------------
\setenumerate[1,2,3]{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt}
\setitemize[1,2,3]{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt,align=left}
\setdescription{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt,align=left}
%indent for items-------------------------------------------
\setlist[enumerate]{leftmargin=\parindent,align=left,labelwidth=\parindent,labelsep=0em}%
\setlist[itemize]{leftmargin=0.5\parindent,align=left,labelwidth=0.5\parindent,labelsep=0em}
%%%define a new quotation%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\renewenvironment{quotation}
{\list{}{\listparindent 2em%equal to \parindent
\partopsep 0.3\baselineskip plus 0.2ex minus 0.1ex%equal to \parskip
\topsep 0em%here
\itemindent 2em%equal to \parindent
\rightmargin 2em%equal to \parindent
\leftmargin 2em%equal to \parindent
\parsep 0.3\baselineskip plus 0.2ex minus 0.1ex%equal to \parskip
}%
\item\relax}
{\endlist}
\makeatother
\begin{document}
\lipsum[1][1-3]
\begin{quotation}
\lipsum[2][1-3]
\end{quotation}
\lipsum[3][1-3]
\begin{enumerate}
\item \lipsum[4][1-3]
\item \lipsum[5][1-3]
\begin{quotation}
\lipsum[6][1-3]
\end{quotation}
\lipsum[7][1-3]
\end{enumerate}
\end{document}
如你所见,enumerate 环境中第一个引号前后的空格是合适的,而 enumerate 环境中第二个引号前后的空格是不合适的。那么如何达到下列目标?
- 枚举内外引号前后的空格相同;
- 引号前后的空格都等于
\parskip
。
答案1
试试这个代码。在环境中使用时,它会在引号环境前后添加空格enumerate
。
使用环境\parskip
中的定义list
来更改引号前后的空格。
\documentclass{article}
\usepackage{lipsum,indentfirst}
\setlength{\parindent}{2em}
\setlength{\parskip}{0.3\baselineskip plus 0.2ex minus 0.1ex}
%%%enumerate and so on%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{enumitem}
%space for items--------------------------------------------
\setenumerate[1,2,3]{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt}
\setitemize[1,2,3]{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt,align=left}
\setdescription{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt,align=left}
%indent for items-------------------------------------------
\setlist[enumerate]{leftmargin=\parindent,align=left,labelwidth=\parindent,labelsep=0em}%
\setlist[itemize]{leftmargin=0.5\parindent,align=left,labelwidth=0.5\parindent,labelsep=0em}
%%%define a new quotation%%%%%%%%%%%%%%%%%%%%%%
\renewenvironment{quotation}
{\par\list{}{% changed <<<<<<<<<<
\setlength{\parskip}{0.5\baselineskip plus 0.2ex minus 0.1ex}% use this <<<<<<<<<<<<
\setlength{\partopsep}{\parskip}%
\setlength{\parsep}{\parskip}%
\setlength{\topsep}{0em}%
\setlength{\leftmargin}{2em}%
\setlength{\rightmargin}{2em}%
\setlength{\itemindent}{2em}%
}
\item[]}
{\endlist}
\begin{document}
\lipsum[1][1-3]
\begin{quotation}
\lipsum[2][1-3]
\end{quotation}
\lipsum[3][1-3]
\begin{enumerate}
\item \lipsum[4][1-3]
\item \lipsum[5][1-3]
\begin{quotation}
\lipsum[6][1-3]
\end{quotation}
\lipsum[7][1-3]
\end{enumerate}
\lipsum[1][1-3]
\end{document}
选项使用 LaTeXquotation
环境,定义为:
\renewenvironment{quotation}{\list{}{%
\listparindent 20pt%
\itemindent\listparindent%
\rightmargin\leftmargin}%
\item[]}
{\endlist}
\documentclass{article}
\usepackage{lipsum,indentfirst}
\setlength{\parindent}{2em}
\setlength{\parskip}{0.3\baselineskip plus 0.2ex minus 0.1ex}
%%%enumerate and so on%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{enumitem}
%space for items--------------------------------------------
\setenumerate[1,2,3]{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt}
\setitemize[1,2,3]{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt,align=left}
\setdescription{itemsep=0pt,partopsep=0.3\baselineskip plus 0.2ex minus 0.1ex,parsep=0pt,topsep=0pt,align=left}
%indent for items-------------------------------------------
\setlist[enumerate]{leftmargin=\parindent,align=left,labelwidth=\parindent,labelsep=0em}%
\setlist[itemize]{leftmargin=0.5\parindent,align=left,labelwidth=0.5\parindent,labelsep=0em}
\begin{document}
\lipsum[1][1-3]
\begin{quotation}
\lipsum[2][1-3]
\end{quotation}
\lipsum[3][1-3]
\begin{enumerate}
\item \lipsum[4][1-3]
\item \lipsum[5][1-3]
\begin{quotation}
\lipsum[6][1-3]
\end{quotation}
\lipsum[7][1-3]
\end{enumerate}
\lipsum[1][1-3]
\end{document}