![\setlength\itemsep 抛出一个奇怪的错误](https://linux22.com/image/385681/%5Csetlength%5Citemsep%20%E6%8A%9B%E5%87%BA%E4%B8%80%E4%B8%AA%E5%A5%87%E6%80%AA%E7%9A%84%E9%94%99%E8%AF%AF.png)
我必须编辑一个 LaTeX 模板以完成一项作业,该作业涉及解决多项选择题。其中一个问题的代码如下:
\begin{list}{$\square$}{}
\setlength\itemsep{-1.5em}
\item The current observation $x_t$ is conditionally independent of all
other observations given the current state $y_t$\\
\item The current observation $x_t$ is conditionally independent of all
other states given the current state $y_t$\\
\item The current state $y_t$ is conditionally independent of all states given the previous state $y_{t-1}$\\
\item The current observation $x_t$ is conditionally independent of $x_{t-2}$ given the previous observation $x_{t-1}$.\\
\item None of the above
\end{list}
问题是我不知道如何标记我的答案(这些选项中只有两个是正确的,应该用黑色方块标记)。我尝试{$\square$}
从第一行中删除,并$\square$
在每个项目旁边添加,在$\blacksquare$
我想要标记的选项旁边添加。
\begin{list}{}
\setlength\itemsep{-1.5em}
\item $\square$ The current observation $x_t$ is conditionally independent
of all other observations given the current state $y_t$\\
\item $\square$ The current observation $x_t$ is conditionally independent
of all other states given the current state $y_t$\\
\item $\square$ The current state $y_t$ is conditionally independent of all
states given the previous state $y_{t-1}$\\
\item $\square$ The current observation $x_t$ is conditionally independent
of $x_{t-2}$ given the previous observation $x_{t-1}$.\\
\item $\square$ None of the above
\end{list}
这对于上一个问题有效。但是对于这个问题,当我执行并编译时,发生了这种情况。
就是那个讨厌的 !-1.5em。我不知道如何去掉它。我尝试删除,\setlength\itemsep{-1.5em}
但这会导致项目之间的间距增加到默认值,并且此页面的内容会溢出到下一页,这对于自动评分器来说是不可接受的。我该怎么办?这非常烦人。
这是我在该行遇到的错误\setlength\itemsep{-1.5em}
。 (正如答案所说,我也尝试过将其放在\itemsep
花括号中,但无济于事。)
答案1
环境list
需要两个参数,而在第二个示例中,您只输入了一个参数。因此,它使用下一个标记(即)\setlength
作为其第二个参数。因此,使用\begin{list}{}{}
而不是\begin{list}{}
可以消除错误。
至于您最初试图解决的问题:\item
宏有一个可选参数,您可以使用它来指定其标签。因此,下面的代码应该可以满足您的要求。
\documentclass{article}
\usepackage{amssymb} %% <- for \square and \blacksquare
\begin{document}
\begin{list}{$\square$}{}
\setlength\itemsep{-.4em}
\item The current observation $x_t$ is conditionally independent of all
other observations given the current state $y_t$
\item[$\blacksquare$] The current observation $x_t$ is conditionally independent of all
other states given the current state $y_t$
\item[$\blacksquare$] The current state $y_t$ is conditionally independent of all states given the previous state $y_{t-1}$
\item The current observation $x_t$ is conditionally independent of $x_{t-2}$ given the previous observation $x_{t-1}$.
\item None of the above
\end{list}
\end{document}
你可以通过定义来节省一些输入
\newcommand*\correctitem{\item[$\blacksquare$]}
并使用它而不是每次都输入它。
顺便说一句,第二个参数的内容list
是在实际列表开始之前执行的。将其放在\setlength\itemsep{-.4em}
这个参数中会更合适,如下所示:
\begin{list}{$\square$}{\setlength\itemsep{-.4em}}
因为\itemsep
这没什么区别,但是如果你想设置例如\topsep
,在环境内这样做实际上已经太晚了。
答案2
您不需要疯狂地设置,只需使用带有选项的包\itemsep
即可。enumitem
nosep
\documentclass{article}
\usepackage{amssymb}
\usepackage{enumitem}
\renewcommand{\labelitemi}{$\square$}
\begin{document}
\begin{itemize}[nosep]
\item The current observation $x_t$ is conditionally independent of all
other observations given the current state $y_t$
\item[$\blacksquare$] The current observation $x_t$ is conditionally independent of all
other states given the current state $y_t$
\item[$\blacksquare$] The current state $y_t$ is conditionally independent of all states given the previous state $y_{t-1}$
\item The current observation $x_t$ is conditionally independent of $x_{t-2}$ given the previous observation $x_{t-1}$.
\item None of the above
\end{itemize}
\end{document}