我正在输入家庭作业问题,我想要一种非常具体的格式,但我不知道从哪里开始。我希望练习编号排列在一列中,然后问题和答案与另一“列”对齐。为了了解我的意思,这个简单的代码可以工作:
\documentclass{article}
\begin{document}
\begin{tabular}{l l}
5. & This is the question \\
& This is where the answer goes \\
11. & Another Questions \\
& Another Answer
\end{tabular}
\end{document}
这看起来就是我想要的,但把整个作业放在表格环境中并担心对齐字符等很烦人。我真正想要的是一个可以指定练习编号的环境,它会为问题和答案创建适当的布局。这可能吗?谢谢!
答案1
有很多方法可以做到这一点。一个简单的方法就是使用enumerate
环境
\begin{enumerate}
\item[5] This is the question.
\item[] This is where the answer goes
\end{enumerate}
或者也许您想要自己的环境;我在下面发布了几个不同的选项 - 任您挑选,或者基于其中一个构建一个。
\documentclass{article}
\usepackage{calc}
\newcommand{\question}[1]{\item[#1]}
\newcommand{\answer}{\item[]}
\newenvironment{questionandanswer}[2]{\enumerate\setcounter{enumi}{#2-1}\item#1\item[]}{\endenumerate}
\newenvironment{anotherapproach}{\enumerate}{\endenumerate}
\begin{document}
\begin{questionandanswer}{This is the question.}{5}
This is where the answer goes
\end{questionandanswer}
\begin{anotherapproach}
\question{5} This is the question.
\answer This is where the answer goes
\end{anotherapproach}
\begin{enumerate}
\item[5] This is the question.
\item[] This is where the answer goes
\end{enumerate}
\end{document}
如果你想改变环境的缩进enumerate
,那么enumitem
包是最明智的做法:
\documentclass{article}
\usepackage{calc}
\usepackage{enumitem}
\setlist[enumerate]{leftmargin=*}
答案2
您可以使用enumerate
环境;可选参数\item
允许您分配所需的标签:
\documentclass{article}
\usepackage[nopar]{lipsum}% just to generate text for the example
\begin{document}
\begin{enumerate}
\item This is the question.
And this is where the question goes. \lipsum[2]
\item[11.] This is another question.
And this is where the question goes. \lipsum[4]
\end{enumerate}
\end{document}
答案3
如果您对标签之间的间距有特别要求,那么从 Gonzalo 的答案中复制并进行适当修改的以下代码对我来说看起来不错:
\documentclass{article}
\usepackage{enumitem}%provides the key labelsep
\begin{document}
\begin{enumerate}[labelsep=*]
\item[5.] This is the question.
And this is where the question goes. I use \texttt{labelsep}=*
\item[11.] This is another question.
And this is where the question goes. I use \texttt{labelsep}=*
\end{enumerate}
\begin{enumerate}
\item[5.] This is the question.
And this is where the question goes. No \texttt{labelsep}=*
\item[11.] This is another question.
And this is where the question goes. No \texttt{labelsep}=*
\end{enumerate}
\end{document}
输出: