1

I would like to indent the first line of list items in enumerate. To do this, I have defined several kinds of enumerate-like environments (see below).

In enumerateI, I just use a non-zero \itemindent. All the labels are then moved to the right compared to the standard enumerate. The distance between "2." and "(a)" on line "ZZZ" is wrong too.

In enumerateII, I add \itemindent to \labelsep. Labels on lines "XXX", "YYY" and "WWW" are then at the same position as with enumerate, but the "(a)" on line "ZZZ" is not vertically aligned with the "(a)" and "(b)" on lines "YYY" and "WWW".

In enumerateIII, I set \itemindent to 0 if @noparlist is true. The alignment of "(a)" on line "ZZZ is now correct, but this time, "WWW" is not indented anymore and "(b)" is not vertically aligned with the "(a)"'s.

[Note: I have tested @noparlist, but I don't understand how this switch differs from @inlabel and @noparitem. LaTeX's "source2e" is quite obscure about this, so if someone could clarify the meaning of these switches, I would really appreciate that. Should this be a separate question? Anyway, in the cases considered here, it makes no difference.]

I have also tried to modify the lines containing \itemindent in the definition of \@item from "latex.ltx", but without success.

So, my question is the following: how to get the same alignment as with enumerateII on lines "XXX", "YYY" and "WWW", and the same as with enumerateIII on line "ZZZ"? I know that similar questions have already been asked before, but I would like an automatic solution not using the enumitem package. Redefining \@item is acceptable, if not too daring.

Here is my code:

\documentclass{article}

\makeatletter

\newlength\standardlabelsep
\setlength\standardlabelsep{5pt}
\newlength\myitemindent
\setlength\myitemindent{\parindent}

\newenvironment{enumerateI}{%
  \begin{enumerate}%
    \setlength\itemindent{\myitemindent}%
    \setlength\labelsep{\standardlabelsep}%
  }{\end{enumerate}}

\newenvironment{enumerateII}{%
  \begin{enumerate}%
    \setlength\itemindent{\myitemindent}%
    \setlength\labelsep{\standardlabelsep}%
    \addtolength\labelsep{\itemindent}%
  }{\end{enumerate}}

\newenvironment{enumerateIII}{%
  \begin{enumerate}%
    \setlength\itemindent{\myitemindent}%
    \setlength\labelsep{\standardlabelsep}%
    \addtolength\labelsep{\myitemindent}%
    \if@noparlist
       \setlength\itemindent{0pt}%
    \fi
  }{\end{enumerate}}

\newcommand\XXX{XXX\dotfill\break xxx\dotfill\hfill}
\newcommand\YYY{YYY\dotfill\break yyy\dotfill\hfill}
\newcommand\ZZZ{ZZZ\dotfill\break zzz\dotfill\hfill}
\newcommand\WWW{WWW\dotfill\break www\dotfill\hfill}

\makeatother

\begin{document}

Standard \verb|enumerate|:
\begin{enumerate}
\item
  \XXX
  \begin{enumerate}
  \item
    \YYY
  \end{enumerate}
\item
  \begin{enumerate}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerate}
\end{enumerate}

\verb|enumerateI|:
\begin{enumerateI}
\item
  \XXX
  \begin{enumerateI}
  \item
    \YYY
  \end{enumerateI}
\item
  \begin{enumerateI}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerateI}
\end{enumerateI}

\verb|enumerateII|:
\begin{enumerateII}
\item
  \XXX
  \begin{enumerateII}
  \item
    \YYY
  \end{enumerateII}
\item
  \begin{enumerateII}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerateII}
\end{enumerateII}

\verb|enumerateIII|:
\begin{enumerateIII}
\item
  \XXX
  \begin{enumerateIII}
  \item
    \YYY
  \end{enumerateIII}
\item
  \begin{enumerateIII}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerateIII}
\end{enumerateIII}

\end{document}
6
  • Enclose nested list in minipage, something like this: \begin{minipage}[t]{\textwidth-\itemindent-\leftmargini} \begin{{enumerateII} ... \end{enumerateII} \end{minipage}. For this you need add package calc in document preamble.
    – Zarko
    Dec 20, 2015 at 12:21
  • list in minipage` have different margins, see the latex.ltx 'manual' ;-)
    – user31729
    Dec 20, 2015 at 13:39
  • IIRC, enumarate uses \leftskip and \llap to implement the indentation. Each layer simply increases \leftskip. Dec 20, 2015 at 15:52
  • @Zarko Enclosing nested lists in minipage is not an automatic solution. I would prefer to use the standard LaTeX syntax but redefine enumerate and, if needed, \@item. To do this, I would need to understand how this macro works, in particular the meaning of the switches @inlabel, @noparitem and @noparlist... Dec 20, 2015 at 22:17
  • Why don't you like enumitem?
    – cfr
    Dec 21, 2015 at 0:12

1 Answer 1

1

With enumitem, the best I could find is the answer to Custom enumerate margin with enumitem . Unfortunately, "[before=\trickindent]" has to be inserted by hand after an inner \begin{enumerate} every time the latter is the first thing following \item. Another problem is that the label is shifted horizontally compared to the case where \itemindent is zero.

Without enumitem, a solution is to modify \@item as in the code below. The modified version, \modified@item, differs from the original one in that \itemindent is not inserted inside the label box but at the end of the \everypar (I hope this is the right place). After \let\@item\modified@item, both enumerate and itemize are modified. Because of the "\ifdim...", this happens only if \itemindent is positive, so environments such as description or verse are untouched. This seems to work, but there may be side effects if other environments than enumerate and itemize are wrongly modified.

Note: I won't accept my answer, in case someone comes with a better one.

Here is the code:

\documentclass{article}

\makeatletter

\def\modified@item[#1]{%
  \if@noparitem
    \@donoparitem
  \else
    \if@inlabel
      \indent \par
    \fi
    \ifhmode
      \unskip\unskip \par
    \fi
    \if@newlist
      \if@nobreak
        \@nbitem
      \else
        \addpenalty\@beginparpenalty
        \addvspace\@topsep
        \addvspace{-\parskip}%
      \fi
    \else
      \addpenalty\@itempenalty
      \addvspace\itemsep
    \fi
    \global\@inlabeltrue
  \fi
  \everypar{%
    \@minipagefalse
    \global\@newlistfalse
    \if@inlabel
      \global\@inlabelfalse
      {\setbox\z@\lastbox
       \ifvoid\z@
         \kern-\itemindent
       \fi}%
      \box\@labels
      \penalty\z@
    \fi
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi
    \ifdim\itemindent>\z@\kern\itemindent\fi % Added.
  }%
  \if@noitemarg
    \@noitemargfalse
    \if@nmbrlist
      \refstepcounter\@listctr
    \fi
  \fi
  \sbox\@tempboxa{\makelabel{#1}}%
  \global\setbox\@labels\hbox{%
    \unhbox\@labels
    \ifdim\itemindent>\z@\else\hskip \itemindent\fi % Original without `\ifdim`.
    \hskip -\labelwidth
    \hskip -\labelsep
    \ifdim \wd\@tempboxa >\labelwidth
      \box\@tempboxa
    \else
      \hbox to\labelwidth {\unhbox\@tempboxa}%
    \fi
    \hskip \labelsep}%    
  \ignorespaces}

\newlength\standardlabelsep
\setlength\standardlabelsep{5pt}
\newlength\myitemindent
\setlength\myitemindent{\parindent}

\newenvironment{enumerateI}{%
  \begin{enumerate}%
    \setlength\itemindent{\myitemindent}%
    \setlength\labelsep{\standardlabelsep}%
  }{\end{enumerate}}

\newcommand\XXX{XXX\dotfill\break xxx\dotfill\hfill}
\newcommand\YYY{YYY\dotfill\break yyy\dotfill\hfill}
\newcommand\ZZZ{ZZZ\dotfill\break zzz\dotfill\hfill}
\newcommand\WWW{WWW\dotfill\break www\dotfill\hfill}

\makeatother

\begin{document}

\verb|enumerate| with the original \verb|\@item|:
\begin{enumerate}
\item
  \XXX
  \begin{enumerate}
  \item
    \YYY
  \end{enumerate}
\item
  \begin{enumerate}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerate}
\end{enumerate}

\verb|enumerateI| with the original \verb|\@item|:
\begin{enumerateI}
\item
  \XXX
  \begin{enumerateI}
  \item
    \YYY
  \end{enumerateI}
\item
  \begin{enumerateI}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerateI}
\end{enumerateI}

\verb|description| with the original \verb|\@item|:
\begin{description}
\item[AAA.]
  \XXX
  \begin{description}
  \item[BBB.]
    \YYY
  \end{description}
\item[CCC.]
  \begin{description}
  \item[DDD.]
    \ZZZ
  \item[EEE.]
    \WWW
  \end{description}
\end{description}

\makeatletter
\let\@item\modified@item
\makeatother

\verb|enumerate| with the modified \verb|\@item|:
\begin{enumerate}
\item
  \XXX
  \begin{enumerate}
  \item
    \YYY
  \end{enumerate}
\item
  \begin{enumerate}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerate}
\end{enumerate}

\verb|enumerateI| with the modified \verb|\@item|:
\begin{enumerateI}
\item
  \XXX
  \begin{enumerateI}
  \item
    \YYY
  \end{enumerateI}
\item
  \begin{enumerateI}
  \item
    \ZZZ
  \item
    \WWW
  \end{enumerateI}
\end{enumerateI}

\verb|description| with the modified \verb|\@item|:
\begin{description}
\item[AAA.]
  \XXX
  \begin{description}
  \item[BBB.]
    \YYY
  \end{description}
\item[CCC.]
  \begin{description}
  \item[DDD.]
    \ZZZ
  \item[EEE.]
    \WWW
  \end{description}
\end{description}

\end{document}

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.