如何在嵌套枚举中实现“无”或更好的“leftmargin = *来自主枚举”缩进?

如何在嵌套枚举中实现“无”或更好的“leftmargin = *来自主枚举”缩进?

我在 a 内部使用 enumeratetabularx并删除了垂直间距。我还将第一级的缩进设置为leftmargin=*,这会导致正确的缩进。

现在我希望枚举的第二级缩进位于同一位置,但我不知道必须在那里设置哪个值。

目前我将左边距设置为 0em,但是现在枚举开始得太靠左边了。

这是我的 MWE:

\documentclass{scrbook}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage{booktabs}%For Table-lines
\usepackage{tabularx}
\AtBeginEnvironment{tabularx}{
\setlist[enumerate, 1]{wide, leftmargin=*, itemsep=0pt, before=\vspace{-\dimexpr\baselineskip +2 \partopsep}, after=\vspace{-\baselineskip}}
\setlist[enumerate, 2]{leftmargin=0em}}
% Remove vertical space inside tabubarx-environement

\begin{document}
    \begin{table}
        \centering
        \caption{Description}
        \begin{tabularx}{\textwidth}{lp{.7\textwidth}}
            \toprule
            Name & Test\\
            Main Course & \begin{enumerate}
                \item Hello World
                \item I am right indented.
            \end{enumerate}\\
            \midrule 
            Extensions & \begin{enumerate}[label={1\alph*}]
                \item Hello World
                \item The Bartender changes 
                \begin{enumerate}[label*={\arabic*}]
                    \item Too far left
                \end{enumerate}
            \end{enumerate}\\
            \bottomrule
        \end{tabularx}%
    \end{table}
\end{document}

我喜欢绿色缩进,但不喜欢红色突出显示。

MWE 示例

答案1

enumtab这将创建一个结合了tabularx和功能的新环境enumerate。对于嵌套级别 1-4,可以\item使用\itemi\itemii\itemiii\itemiv。可以使用 来终止缩进\par\leftskip=0pt

我任意将缩进设置为1.2em、2em、2em和2.3em。

演示

\documentclass{scrbook}
\usepackage{enumitem}% not used here
\usepackage{etoolbox}% also not used
\usepackage{booktabs}%For Table-lines
\usepackage{tabularx}
\usepackage{blindtext}

\renewcommand{\theenumiii}{\arabic{enumiii}}

\makeatletter
\@addtoreset{enumii}{enumi}
\@addtoreset{enumiii}{enumii}
\@addtoreset{enumiv}{enumiii}
\makeatother

\newenvironment{enumtab}% use same arguments as tabularx
 {\setcounter{enumi}{0}%
  \def\itemi{\stepcounter{enumi}%
    \par\leftskip=1.2em\hspace*{-\leftskip}%
    \makebox[\leftskip][l]{\theenumi.}}%
  \def\itemii{\stepcounter{enumii}%
    \par\leftskip=2em\hspace*{-\leftskip}%
    \makebox[\leftskip][l]{\theenumi\theenumii}}%
  \def\itemiii{\stepcounter{enumiii}%
    \par\leftskip=2em\hspace*{-\leftskip}%
    \makebox[\leftskip][l]{\theenumi\theenumii\theenumiii}}%
  \def\itemiv{\stepcounter{enumiv}%
    \par\leftskip=23em\hspace*{-\leftskip}%
    \makebox[\leftskip][l]{\theenumi\theenumii\theenumiii\theenumiv}}%
  \tabularx}{\endtabularx}

\begin{document}
    \begin{table}
        \centering
        \caption{Description}
        \begin{enumtab}{\textwidth}{lX}
            \toprule
            Name & Test\\
            Main Course &
                \itemi \blindtext
                \itemi I am right indented.
            \\
            \midrule 
            Extensions &
                \itemii Hello World
                \itemii The Bartender changes
                \itemiii Too far left
            \\
            \bottomrule
        \end{enumtab}%
    \end{table}
\end{document}

答案2

给你。我擅自用一个\compress命令简化了列表中的间距调整:

\documentclass{scrbook}
\usepackage{enumitem}
\usepackage{etoolbox}
\usepackage{booktabs}%For Table-lines
\usepackage{tabularx, caption}
\makeatletter
    \newcommand*{\compress}{\@minipagetrue}
    \makeatother
\AtBeginEnvironment{tabularx}{
\setlist[enumerate, 1]{wide, leftmargin=*, itemsep=0pt, before=\compress, after=\vspace{-\baselineskip}}
\setlist[enumerate, 2]{leftmargin=0em}}
% Remove vertical space inside tabubarx-environement

\begin{document}
    \begin{table}
        \centering
        \caption{Description}
        \begin{tabularx}{\textwidth}{lp{.7\textwidth}}
            \toprule
            Name & Test\\
            Main Course & \begin{enumerate}
                \item Hello World
                \item I am right indented.
            \end{enumerate}\\
            \midrule
            Extensions & \begin{enumerate}[label={1\alph*}]
                \item Hello World
                \item The Bartender changes
                \begin{enumerate}[label*={\arabic*}, wide = 0pt, leftmargin= *]
                    \item Too far left
                \end{enumerate}
            \end{enumerate}\\
            \bottomrule
        \end{tabularx}%
    \end{table}

\end{document} 

在此处输入图片描述

相关内容