我的文档中有许多问题,有些问题包含可枚举的项目,有些问题则没有项目。我希望每个问题的正文都有类似的边距,无论内容如何。
我目前的解决方法是将没有可枚举项的问题文本放入没有项的描述中。Latex 将编译此操作,但会产生错误。我如何才能轻松实现相同的格式而不导致错误?
\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb,xfrac}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newenvironment{theorem}[2][Theorem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{lemma}[2][Lemma]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{exercise}[2][Exercise]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{question}[2][Question]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\newenvironment{corollary}[2][Corollary]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}
\linespread{1.5}
\begin{document}
\begin{question}{1}\hfill
\begin{enumerate}
\item
$\text{average traffic per user} = 100kbps \times 0.1 = 10kbps$ \\
$\text{peak traffic per user} = 100kbps$
\end{question}
\begin{question}{2}\hfill
\begin{description}
$P_n=(1-\rho)\rho^n$ \\
$\rho = \sfrac{5.4}{6.0} = 0.9$ \\
$B = 50, N > B \longrightarrow N >= B + 1$ \\
$P_N = 1 - \sum_{b}^{B+1}P_{b} = 0.004638397686588025 \approx 0.464\%$ \\
The packet loss probability due to buffer overflow is $0.464\%$. \\
\end{description}
\end{question}
\end{document}
错误
ERROR: LaTeX Error: \begin{enumerate} on input line 32 ended by \end{trivlist}.
--- TeX said ---
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.36 \end{question}
--- HELP ---
No help available
答案1
您没有提供可用的示例,因此我无法显示输出,但在所有使用的列表环境中,\item
您可以使用可选参数指定不同的标签,从而\item[]
完全不指定标签。事实上,这就是大多数 latex 显示环境(例如center
等quote
)的定义方式,即没有标签的单项列表。