在枚举级别 II 中对齐文本

在枚举级别 II 中对齐文本

我对 LaTEX 还不熟悉。我正在编写一个大型文档,其中需要对每个条款进行编号,因此我使用 LaTEX 中的枚举功能,效果很好。有时我需要在 2 个或更多级别中编写条款。因此我使用嵌套的“枚举”解决方案。但是当我转到级别 II 时,特定条款的第一行中有一个小的额外空间。但是,条款的其余行完全符合要求。在枚举级别 I 中编写文本时不会出现此问题。我如何编辑以便枚举级别 II 或更高级别也显示与级别 I 中一样完全对齐的文本?

请帮忙!!!

最小代码示例如下:

\documentclass[a4paper, 12pt, twoside]{thesis}

\usepackage[square, numbers, comma, sort&compress]{natbib}

\usepackage{verbatim} 

\usepackage{lipsum}  

\usepackage{textcomp}

\usepackage{vector} 

\usepackage{url}
\usepackage{natbib}

\usepackage[compact]{titlesec}

\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{01pt}{\Huge}
\titlespacing*{\chapter}{0pt}{01pt}{01pt}

\setlength{\parskip}{6pt}

\usepackage{fancyhdr}

\usepackage[document]{ragged2e}

\usepackage{enumitem}
\usepackage{etoolbox}

\usepackage{array}

\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\huge}

\titleformat{\section}{\normalfont\upshape\bfseries}{\thesection}{2.7em}{\large}

\titleformat{\subsection}{\normalfont\upshape}{\thesubsection}{2.5em}{\normalsize}

\titleformat{\paragraph}{\normalfont\upshape}{\thesubsection}{1em}{\normalsize}

\setcounter{secnumdepth}{4}

\begin{document}
\mainmatter

\pagestyle{fancy} 

\renewcommand{\chaptermark}[1]{ \markboth{#1}{} }
\renewcommand{\sectionmark}[1]{ \markright{#1}{} }
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}%

\addtocontents{toc}{\vspace{2em}} 

\justifying

\pretolerance=10000

\begin{enumerate}[leftmargin=4.5em,labelsep=2.7em,align=right,label={\thesection.\arabic*}]

\item \lipsum

\vspace{0.5em}

\begin{itemize}

\item \lipsum

\end{itemize}

\end{enumerate}

\end{document}

答案1

此解决方案在开始枚举之前存储默认值。或者,您可以使用,[labelwidth=*, labelsep=*]但结果不太一样。

\documentclass[a4paper, 12pt, twoside]{thesis}

\usepackage[square, numbers, comma, sort&compress]{natbib}

\usepackage{verbatim} 

\usepackage{lipsum}  

\usepackage{textcomp}

\usepackage{vector} 

\usepackage{url}
\usepackage{natbib}

\usepackage[compact]{titlesec}

\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{01pt}{\Huge}
\titlespacing*{\chapter}{0pt}{01pt}{01pt}

\setlength{\parskip}{6pt}

\usepackage{fancyhdr}

\usepackage[document]{ragged2e}

\usepackage{enumitem}
\usepackage{etoolbox}

\usepackage{array}

\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\huge}

\titleformat{\section}{\normalfont\upshape\bfseries}{\thesection}{2.7em}{\large}

\titleformat{\subsection}{\normalfont\upshape}{\thesubsection}{2.5em}{\normalsize}

\titleformat{\paragraph}{\normalfont\upshape}{\thesubsection}{1em}{\normalsize}

\setcounter{secnumdepth}{4}
\newcommand{\normalwidth}{}% reserve global names
\newcommand{\normalsep}{}

\begin{document}
\mainmatter

\pagestyle{fancy} 

\renewcommand{\chaptermark}[1]{ \markboth{#1}{} }
\renewcommand{\sectionmark}[1]{ \markright{#1}{} }
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}%

\addtocontents{toc}{\vspace{2em}} 

\justifying

\pretolerance=10000

\edef\normalwidth{\the\labelwidth}%
\edef\normalsep{\the\labelsep}%

\begin{enumerate}[leftmargin=4.5em,labelsep=2.7em,align=right,label={\thesection.\arabic*}]

\item \lipsum[1-2]

\vspace{0.5em}

\item \the\labelwidth~\the\labelsep

\begin{itemize}[labelwidth=\normalwidth, labelsep=\normalsep]
\item \the\labelwidth~\the\labelsep
\item \lipsum[3-4]
\end{itemize}

\begin{itemize}[labelwidth=*, labelsep=*]
\item \the\labelwidth~\the\labelsep
\item \lipsum[3-4]
\end{itemize}

\end{enumerate}

\end{document}

相关内容