關於枚舉環境的行為

關於枚舉環境的行為

我為作業問題定義了一個非常簡單的自訂環境,基本上它只是enumerate但沒有縮排:

\newcounter{hwprob}
\newenvironment{hwprob}{\refstepcounter{hwprob} \textbf{\thehwprob.} ~ }{}

如果我enumerate在裡面打開一個實際環境hwprob,會發生這種情況:

\begin{hwprob}
   \begin{enumerate}
      \item Some text.
      \item Some other text.
   \end{enumerate}
\end{hwprob}

我不知道為什麼第一項 1. 不與以下項目在同一行開始1.我嘗試刪除波形符,但無濟於事。讓我困惑的是,我知道在環境enumerate內部使用時proof,第一個項目將與證明。,具有正確的縮排等等。

我可以做什麼來解決這個問題?這是我定義的結果hwprob,還是固有的enumerate

答案1

這是「如何」部分:定義為清單環境,並在 的開頭hwprob自動插入。\itemhwprob

\documentclass{article}
\usepackage{enumitem}

\newlist{hwprob}{enumerate}{1}
\setlist[hwprob]{label=\textbf{\arabic*.}, first*=\item}

\begin{document}
\begin{hwprob}
   \begin{enumerate}
      \item Some text.
      \item Some other text.
   \end{enumerate}
\end{hwprob}
\end{document}

在此輸入影像描述

\trivlist對於“為什麼”部分,我猜它與(可能與)有關\parshape,這是列表和定理環境使用的共同基礎。

答案2

如果環境在一個 LaTeX或環境中啟動,則您希望實現的格式設定(使清單中的第一項enumerate從目前行開始而不是在換行符之後開始)會發生。enumeratelisttrivlist

為了實現您的格式化目標,我建議您載入 enumitem 套件並使用它的\newlist\setlist巨集來建立一個名為 的自訂的類似枚舉的清單環境hwprob

在此輸入影像描述

\documentclass{article}
\usepackage{enumitem}
\newlist{hwprob}{enumerate}{1}
\setlist[hwprob,1]{label=\bfseries\arabic*.,left=0pt}

\begin{document}
\begin{hwprob}
\item
   \begin{enumerate}
      \item Some text.
      \item Some other text.
   \end{enumerate}
\end{hwprob}
\end{document}

相關內容