7

In a theorem-like environment that begins with a (parenthesized) enumeration, how can the horizontal extra space before the item be eliminated but:

  • without destroying correct indentation of the body of the items, including lines after the first one in an item; and

  • without requiring no blank line before the body of the first item; and

  • without unduly shrinking the space between the first item's label and its body text?

In the output from the source below, the first red arrow marks where the extra unwanted horizontal space appears.

As we can see in "1.3 Examples", the attempt to eliminate the extra horizontal space of the first item destroys the uniform horizontal indentation of the first item. In "1.4 Examples", the body of the first item begins a separate paragraph after its label. In "1.5 Examples", the latter issue is avoided by eliminating the blank line in the source, but there is too little space between the first item's label and its body text.

\documentclass{article}
\usepackage[left=1.2in,right=1.2in,top=1in,bottom=1in]{geometry}

\newcommand{\sometxt}{% Some text begins this. The identity is $\sin^2(\theta) + \cos^2(\theta) = 1$ % and in very simple terms $(a + b)^2 \neq a^2 + b^2$.% On the other hand, we do have the basic law of powers that $(a b)^2 = a^2 b^{2}$. }

\usepackage{enumitem} \usepackage{mathtools,amsthm,thmtools}

\newlist{pexenum}{enumerate}{1} \setlist[pexenum,1]{label= \upshape(\arabic*)}

\swapnumbers

\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\declaretheoremstyle[ headfont= \bfseries, headpunct={\bfseries.}, postheadspace=0.5em, spaceabove=12pt,spacebelow=12pt ]{exstyle}

\declaretheorem[ style=exstyle, numberlike=theorem, ] {examples}

\begin{document}

\section{The section}

\noindent This is OK with text within the environment precedes the enumeration:

\begin{examples} Text before the enumeration. \begin{pexenum} \item

  \sometxt      
  \setcounter{pexenumi}{9}
  \item \sometxt

\end{pexenum} \end{examples}

\noindent \textbf{The problem}, when \emph{no} text precedes enumeration---too much horizontal space before 1st label: \begin{examples} \begin{pexenum} \item

  \sometxt
  \setcounter{pexenumi}{9}
  \item \sometxt

\end{pexenum} \end{examples}

\noindent Attempted fix---\verb!leftmargin=*! etc.. \emph{Wrong}---entire 1st item exdented:

% From https://tex.stackexchange.com/a/17487/13492: \begin{examples} \begin{pexenum}[leftmargin=*] \item

  \sometxt
\end{pexenum}\vspace*{-2\partopsep}
\begin{pexenum}[resume]
\setcounter{pexenumi}{9}
  \item \sometxt

\end{pexenum} \end{examples}

\noindent Attempted fix---use \verb!\fixitem!.. \emph{Wrong}---1st item body begins new paragraph after item label:

% From https://tex.stackexchange.com/a/17500/13492: \newcommand*\fixitem{\item[]% \refstepcounter{pexenumi}\hskip-\leftmargin\labelpexenumi\hskip0.5\labelsep}

\begin{examples} \begin{pexenum} \fixitem % The blank line before the item's text is deliberate!

  \sometxt
  \item \sometxt
\setcounter{pexenumi}{9}
  \item \sometxt

\end{pexenum} \end{examples}

\noindent Attempted fix---use \verb!\fixitem!.---no blank line. This works, but \emph{awkward} having to avoid the blank line:

\begin{examples} \begin{pexenum} \fixitem %
\sometxt \item \sometxt \setcounter{pexenumi}{9} \item \sometxt \end{pexenum} \end{examples}

\end{document}

Spacing after label of 1st item in enumerate inside a theorem-like environment

Edit: The @label method shown in https://tex.stackexchange.com/a/17465/13492 seems to work!

Related:

The question is similar to that of Annoying space before the first item in an enumeration which starts a theorem, except that now:

  • the enumeration is done with parenthesized numbers (which may affect spacing); and
  • each item has more than one line, whereas in the original question each item had a single line which obscured the shortcoming in the answers provided there.

The source shows just one method that tries to remove the unwanted horizontal space before the first item, but the other methods given in answers to Annoying space before the first item in an enumeration which starts a theorem suffer the same shortcoming.

See also my "non-answer" https://tex.stackexchange.com/a/586852/13492.

murray
  • 7,944

2 Answers2

3

You can use the first key together with the tricks in this post.

\documentclass{article}

\newcommand{\sometxt}{% Some text begins this. The identity is $\sin^2(\theta) + \cos^2(\theta) = 1$ % and in very simple terms $(a + b)^2 \neq a^2 + b^2$.% On the other hand, we do have the basic law of powers that $(a b)^2 = a^2 b^{2}$. }

\usepackage{enumitem} \usepackage{mathtools,amsthm,thmtools}

\newlist{pexenum}{enumerate}{1} \setlist[pexenum,1]{label= \upshape(\arabic*)}

\swapnumbers

\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\declaretheoremstyle[ headfont= \bfseries, headpunct={\bfseries.}, postheadspace=0.5em, spaceabove=12pt,spacebelow=12pt ]{exstyle}

\declaretheorem[ style=exstyle, numberlike=theorem, ] {examples}

\newcommand*\myfirstitem{\item[]% based on https://tex.stackexchange.com/a/17500 \refstepcounter{pexenumi}\hskip-\leftmargin\labelpexenumi\hskip0.5\labelsep \let\olditem\item \def\item{\let\item\olditem}% }

\begin{document}

\section{The section}

\begin{examples} Text before the enumeration. \begin{pexenum} \item \sometxt \item \sometxt \end{pexenum} \end{examples}

\begin{examples} \begin{pexenum}[first=\myfirstitem] \item \sometxt \item \sometxt \end{pexenum} \end{examples}

\begin{examples} \begin{pexenum}[leftmargin=*] \item \sometxt \end{pexenum}\vspace*{-2\partopsep} \begin{pexenum}[resume] \item \sometxt \end{pexenum} \end{examples}

\end{document}

enter image description here

  • Seems to work perfectly. Limitation: In case of multiple kinds of enumerate environments defied like that for pexenum, we would need corresponding separate versions of myfirsstitem. Caution: would need some change in (unlikely) situation of more than 99 items! – murray Mar 13 '21 at 22:40
  • There is a defect in this myfirst... method: A blank line between the \begin{pexenum}[first=\myfirstitem] and the first \item causes the body of the first item to begin a new paragraph. Ordinarily, blank lines between a \begin{enumerate} and the first \item cause no such behavior. – murray Mar 16 '21 at 19:00
  • @murray This may be but I am not a fan of accepting and unaccepting games, so I wish you good luck with your query. –  Mar 16 '21 at 19:04
  • Sorry, no bad intentions. I discovered the defect later on when I tried it on another document. (The underlying hack you referenced does work, though, even with the blank line before the first item.) – murray Mar 16 '21 at 19:42
  • It does not matter, I quit anyway because of these incidents. This site is not for me. –  Mar 16 '21 at 19:44
1

Is it what you want?

\documentclass{article}

\newcommand{\sometxt}{% Some text begins this. The identity is $\sin^2(\theta) + \cos^2(\theta) = 1$ % and in very simple terms $(a + b)^2 \neq a^2 + b^2$.% On the other hand, we do have the basic law of powers that $(a b)^2 = a^2 b^{2}$. }

\usepackage{enumitem} \usepackage{mathtools,amsthm,thmtools}

\newlist{pexenum}{enumerate}{1} \setlist[pexenum,1]{label= \upshape(\arabic), wide=0pt, leftmargin=}

\swapnumbers

\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\declaretheoremstyle[ headfont= \bfseries, headpunct={\bfseries.}, postheadspace=0.5em, spaceabove=12pt,spacebelow=12pt ]{exstyle}

\declaretheorem[ style=exstyle, numberlike=theorem, ] {examples}

\begin{document}

\section{The section}

\begin{examples} Text before the enumeration. \begin{pexenum} \item \sometxt \item \sometxt \end{pexenum} \end{examples}

\begin{examples} \begin{pexenum} \item \sometxt \item \sometxt \end{pexenum} \end{examples}

\begin{examples} \begin{pexenum}[leftmargin=*] \item \sometxt \end{pexenum}\vspace*{-2\partopsep} \begin{pexenum}[resume] \item \sometxt \end{pexenum} \end{examples}

\end{document}

enter image description here

Edit: I you prefer right-aligned labels in lists, you can use the widest key:

\documentclass{article}
\newcommand{\sometxt}{%
Some text begins this. The identity is $\sin²(θ) + \cos²(θ) = 1$ %
and in very simple terms $(a + b)² ≠ a² + b²$.%
On the other hand, we do have the basic law of powers that $(a b)² = a² b^{2}$.
}

\usepackage{enumitem} \usepackage{mathtools,amsthm,thmtools}

\newlist{pexenum}{enumerate}{1} \setlist[pexenum,1]{label= \upshape(\arabic), widest=99, leftmargin=}

\swapnumbers

\declaretheorem[name=Theorem,numberwithin=section]{theorem}

\declaretheoremstyle[ headfont= \bfseries, headpunct={\bfseries.}, postheadspace=0.5em, spaceabove=12pt,spacebelow=12pt ]{exstyle}

\declaretheorem[ style=exstyle, numberlike=theorem, ] {examples}

\begin{document}

\section{The section}

\begin{examples} Text before the enumeration. \begin{pexenum}[start=9] \item \sometxt \item \sometxt \end{pexenum} \end{examples}

\begin{examples} \begin{pexenum} \item \sometxt \item \sometxt \end{pexenum} \end{examples}

\begin{examples} \begin{pexenum}[leftmargin=*] \item \sometxt \end{pexenum}\vspace*{-2\partopsep} \begin{pexenum}[resume] \item \sometxt \end{pexenum} \end{examples}

\end{document}

enter image description here

Edit: I slighly modified the code for the hack:

   \begin{examples}
        \begin{pexenum}
          \item[(1)\phantom{0}\kern0.05em\stepcounter{pexenumi}]\hskip-0.55em\sometxt
          \item \sometxt
       \end{pexenum}
    \end{example}

enter image

Allok
  • 405
Bernard
  • 271,350
  • 1
    Unfortunately, NO! None of the numerical labels is properly indented so as to allow numbers higher than 9. In the first \begin{enumerate} add \item hello\item hello\item hello\item hello\item hello\item hello\item hello\item\sometxt. Then the numerical labels become left-aligned instead of the normal right-aligned; and the text of the first line of the 10th item is pushed rightwards away from alignment with all the other items' first lines (which is the same as the whole text of the other items). – murray Mar 12 '21 at 01:50
  • I see better. What you want was not quite clear from your post. What would be the maximum value of the labels? – Bernard Mar 12 '21 at 10:03
  • for my purposes, the default maximum of 2 digits is OK. – murray Mar 14 '21 at 18:41
  • @murray: So it's covered by the key used in my edit: widest=99. – Bernard Mar 14 '21 at 19:58
  • Both 1.2 Esamples and 1.3 Examples still have the unwanted extra space between "Examples." and "(1)" that I'm trying to eliminate. – murray Mar 15 '21 at 15:58
  • @murray: this is due to the widest=99 key that saves the necessary space for a two-digit counter and the right alignment of the counters. You can hack using the optional argument of \item, something like \item[(1)\phantom{1}] \stepcounter{pexenumi}. – Bernard Mar 15 '21 at 17:20
  • And that "necessary space for a two-digit counter" and "right alignment" is precisely what I'm trying to get around in the situation of the first item within an enumerate that's inside another environment! – murray Mar 15 '21 at 20:10
  • Did you try the dirty hack to see whether it produces more or less what you want? – Bernard Mar 15 '21 at 20:31
  • which "dirty hack"? – murray Mar 16 '21 at 15:31
  • What I mentioned in thhe last but one comment: use \item[(1)\phantom{1}] \stepcounter{pexenumi} for the first item. – Bernard Mar 16 '21 at 15:38
  • Using \item[(1)\phantom{1}] \stepcounter{pexenumi} for the first item seems to introduce an extra amount of space between the "(1)" label and the text following it. – murray Mar 17 '21 at 19:30
  • Strange… I'll check what can be done – Bernard Mar 17 '21 at 19:46
  • Using \item[(1)\phantom{1}] \stepcounter{pexenumi} for the first item also suffers the limitation that unless you leave no blank line between that and the body text of the first item, that body text begins a new paragraph — unlike the normal situation with an '\item. (That's the same limitation as for answer https://tex.stackexchange.com/a/586917/13492.) – murray Mar 20 '21 at 19:50
  • You can incorporate \stepcounter{pexenumi} to the optional argument of the \item command. – Bernard Mar 20 '21 at 19:55
  • Using \item[(1)\phantom{1}\stepcounter{pexenumi}] takes care of the issue of a blank line preceding the text body of the first item. It still provides too little space between the label "(1)" and the first item's body text; that requires an additional hack, e.g.: \item[(1)\phantom{1}\stepcounter{pexenumi}\hspace{-0.5em}]. – murray Mar 21 '21 at 19:57
  • Please make your hack, with my addendum of \hspace{0.5em} and answer so I can accept it. – murray Mar 23 '21 at 13:46
  • Oops: I'm still getting the original, excessive space before "(1)" when using \item[(1)\phantom{1}\stepcounter{pexenumi}. – murray Mar 23 '21 at 16:07
  • @murray: I've modified the hack. Please see if it corresponds more to what you want now. – Bernard Mar 23 '21 at 20:02
  • The modified hack still has problem that, if there is a blank line between the \item[{1)\phantom... and the body of the item text, then the body text of the first item begins a new pargraph, on a new line of the output (instead of the normal behavior of an enumerate, where the body of the item immediately follows its label). – murray Mar 23 '21 at 21:11
  • Why would you have a blank line between the item label and the body of the item? – Bernard Mar 23 '21 at 21:16
  • I don't want a blank line between the item label and the body of the item. What I do want is, in the .tex source, to have a handy way, both for writing and reading: \begin{examples}\label{blah-blah}, blank line, \item\label[more-blah-blah} blank line, body text of first item, blank line, etc. – murray Mar 24 '21 at 01:06
  • If I understand what you want, it is only for the readability of the code? In this case, replace your blank line with a line with the single comment character (%). – Bernard Mar 24 '21 at 10:23