我正在为我的学生制作一份数学练习清单。下面是我用来创建清单的环境示例:
\documentclass[10pt,a4paper,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcounter{questionnumber}
\newcommand{\makequestion}[2]{\refstepcounter{questionnumber}\par\vspace{1em}\noindent\textbf{(#1\hspace{0mm}-\hspace{0mm}\textbf{#2})\hspace{1mm}Question\hspace{0.3em}\thequestionnumber.}\\\vspace{-4mm}\ignorespaces}
\newcounter{lettercounter}[questionnumber]
\newcommand{\alternative}{(\alph{lettercounter})}
\newenvironment{options}{\begin{list}{\alternative}{\usecounter{lettercounter}}}{\end{list}}
\begin{document}
\makequestion{MIT}{2014}
What do you think about life?
\begin{options}
\item I think it's a word.
\item I think it's not a word.
\end{options}
\makequestion{MIT}{2011}
Is it a boy or a girl?
\begin{options}
\item A boy
\item Yes.
\end{options}
\end{document}
我想在文档末尾制作一个答案,其结构如下:
问题 1 - A
问题 2 - B
但我不知道该怎么做。你能帮助我吗?
答案1
你可以使用专用包,而不是自己定义所有内容,例如exsheets
.然后您可以轻松地在文档末尾打印解决方案:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{exsheets}
% cloning the exercise headings from the question:
\DeclareInstance{exsheets-heading}{myheading}{default}{
join = {
title[l,B]subtitle[r,B](0pt,0pt) ;
title[r,B]number[l,B](.333em,0pt)
} ,
attach = {
main[l,vc]title[l,vc](0pt,0pt) ;
main[r,vc]points[l,vc](\marginparsep,0pt)
}
}
\SetupExSheets{
headings = myheading ,
subtitle-format = \bfseries\mysubtitleformat ,
question/name = Question ,
solution/name = Question
}
\newcommand*\mysubtitleformat[1]{(#1)\space}
% define a list options which enumerates (a), (b), ...
\usepackage{enumitem}
\newlist{options}{enumerate}{1}
\setlist[options]{label=(\alph*)}
\begin{document}
\begin{question}[subtitle=MIT-2014]
What do you think about life?
\begin{options}
\item I think it's a word.\label{MIT-2014-solution}
\item I think it's not a word.
\end{options}
\end{question}
\begin{solution}
\ref{MIT-2014-solution}
\end{solution}
\begin{question}[subtitle=MIT-2011]
Is it a boy or a girl?
\begin{options}
\item A boy
\item Yes.\label{MIT-2011-solution}
\end{options}
\end{question}
\begin{solution}
\ref{MIT-2011-solution}
\end{solution}
\section*{Solutions}
\SetupExSheets{headings = runin}
\printsolutions
\end{document}