6

LaTeX lists are good and bad. They make life much simpler when it comes to left and right margins and vertical spacing. But they do have quirks.

In the following MWE, I have two simple list environments: lista and listb. I'd like lista to have indented paragraphs. and listb not to have indented paragraphs. The set up works fine except if listb is the first paragraph in lista. In this case, listb begins with an indent thanks to the \itemindent setting in lista.

What options do I have to modify lista and/or listb to get consistent behaviour of listb within lista regardless of whether it is the first paragraph or a subsequent paragraph?

The best I have been able to come up with so far is adding something like this to argument #2 of \list in environment listb:

\if@newlist
  \if@minipagefalse
    \leavevmode
    \vspace{\glueexpr -\baselineskip - \parskip}%
  \fi
  \topsep 0pt
\else
  \topsep \listbdefaulttopsep
\fi

but it seems a bit clunky to me and also involves potentially re-adjusting \topsep before the end of the list. I'm also worries that this code isn't robust enough and will fail in too many unexpected circumstances.

MWE

\documentclass{article}
\usepackage{lipsum}
\newenvironment{lista}{%
  \list{}{%
    \topsep 0pt
    \partopsep 0pt
    \leftmargin 0pt
    \rightmargin 0pt
    \itemindent 1.333em
    \listparindent 1.333em
    \labelsep 0pt
    \parsep 0pt
  }%
  \item\relax
}{%
  \endlist
}
\newenvironment{listb}{%
  \list{}{%
    \topsep 0pt
    \partopsep 0pt
    \leftmargin 3em
    \rightmargin 3em
    \itemindent 0pt
    \listparindent 0pt
    \labelsep 0pt
    \parsep 0pt
  }%
  \item\relax
}{%
  \endlist
}
\begin{document}
\begin{lista}
  \textbf{Keep first line indent here.}
  \lipsum[1]
  \begin{listb}
    \lipsum[2]
  \end{listb}
\end{lista}

\bigskip

\begin{lista}
  \begin{listb}
    \textbf{Remove first line indent here.}
    \lipsum[2]
  \end{listb}
\end{lista}
\end{document}

Output

output

8
  • Why in the second case you insert listb into lista? Just insert only listab in text. Is there some special reason that you not do s?
    – Zarko
    Dec 16, 2023 at 11:08
  • @Zarko The same reason you might nest any list, e.g., enumerate in quote. Obviously the example is minimal and not real world. Dec 16, 2023 at 11:20
  • @Zarko, in fact the same behaviour is observed if you put enumerate inside quotation. Sure, the answer could be "Don't ever put enumerate as the first thing inside a quotation environment. But perhaps there are other answers. Dec 16, 2023 at 11:28
  • Is acceptable that you write your list on the following way: \begin{lista}\textbf{Keep first line indent here.} \lipsum[1][1-4] \begin{listb} \lipsum[2][1-3] \end{listb} \end{lista} \begin{lista}~ \begin{listb}\textbf{Remove first line indent here.} \lipsum[2][1-3] \end{listb} \end{lista} ? Observe inserted ~after \begin{lista} in the second case.
    – Zarko
    Dec 16, 2023 at 11:32
  • @Zarko, no. It's for a style file and I'd like to keep standard syntax. Both lista and listb can have optional arguments too. Dec 16, 2023 at 11:34

1 Answer 1

0

You can check with \ifvmode that you're not in a paragraph, and then force horizontal mode with \noindent before listb. But this generates a vertical \baselineskip which should be canceled.

\ifvmode\noindent\vspace{-\baselineskip}\fi

Full example:

\documentclass{article}
\usepackage{lipsum}
\newenvironment{lista}{%
  \list{}{%
    \topsep 0pt
    \partopsep 0pt
    \leftmargin 0pt
    \rightmargin 0pt
    \itemindent 1.333em
    \listparindent 1.333em
    \labelsep 0pt
    \parsep 0pt
  }%
  \item\relax
}{%
  \endlist
}
\newenvironment{listb}{%
  \ifvmode\noindent\vspace{-\baselineskip}\fi
  \list{}{%
    \topsep 0pt
    \partopsep 0pt
    \leftmargin 3em
    \rightmargin 3em
    \itemindent 0pt
    \listparindent 0pt
    \labelsep 0pt
    \parsep 0pt
  }%
  \item\relax
}{%
  \endlist
}
\begin{document}
\begin{lista}
  \textbf{Keep first line indent here.}
  \lipsum[1]
  \begin{listb}
    \lipsum[2]
  \end{listb}
\end{lista}

\bigskip

\begin{lista}
  \begin{listb}
    \textbf{Remove first line indent here.}
    \lipsum[2]
  \end{listb}
\end{lista}
\end{document}

enter image description here

Note that \noindent\vspace{-\baselineskip} is now inserted at start of each lisb created in vertical mode, even if listb is not the first material in lista (eg. if you add a line break before lisb). But I don't think it will be a problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .