0

I use enumerate inside a tabularx and I removed vertical spacing. I also set the indentation of the first level to leftmargin=*, which leads to the right indentation.

Now I want the second level indentation of the enumration to be on the same position, but I don't know which value I would have to set there.

At the moment I set the leftmargin to 0em, but now the enumeration starts too far left.

Here my 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}

I like the green indent, but not the red highlighted.

Example of MWE

  • BTW, If you are going to use tabularx, you really should include at least one X column. – John Kormylo Jan 26 '18 at 14:31
1

This creates a new environment enumtab which combines features of tabularx and enumerate. Instead of \item you use \itemi, \itemii. \itemiii and \itemiv for nested levels 1-4. The indentation can be terminated using \par\leftskip=0pt.

I arbitrarily set the indentation to 1.2em, 2em, 2em and 2.3em.

demo

\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}
  • Hi, this solution seems very awesome, but is it possible to change the third-level iterator to arabic numbers, too? It isn't possible to align the Text of the 2nd and 3rd level items, or?(Like the green highlighting in the picture) – duichwer Jan 26 '18 at 21:26
  • 1
    \renewcommand{\theenumiii}{\arabic{enumiii}} Like I said, I set the indentation to arbitrary numbers. Feel free to use different ones. – John Kormylo Jan 26 '18 at 21:39
  • Thank this works exactly as expected :). If you have time, I would be helpful, If you could add some comments to your solution. (e.g. to the \@addtoreset) – duichwer Jan 26 '18 at 21:49
  • What \@addtoreset does is reset one counter whenever another counter changes. So for example, whenever \itemi use used, enumii is reset to 0. BTW, if you want to use \label, you need to change \stepcounter to \refstepcounter. – John Kormylo Jan 26 '18 at 22:12
0

Here you are. I took the liberty to simplify the spacing adjustments in lists with a \compress command:

\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} 

enter image description here

  • Hi, maybe you understood, my problem wrong. I tried to clarify it with an added image. I want my 2nd level enumerate items on the same indentation like the first level enumerate. – duichwer Jan 25 '18 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.