我需要打印一个与命令创建的框非常相似的框\makeemptybox{\stretch{1}}
,exam.cls
只是我想在框内添加虚线。具体来说,我想先添加 12 条虚线,然后用空白填充框的其余部分(见下图)。
以下是我目前所掌握的信息:
\documentclass[10pt,a4paper,addpoints]{exam}
\begin{document}
\begin{questions}
\question[5] In a class of 30 students, 18 have a dog, 20 have a cat and 3 have neither. A student is selected at random. What is the probability that this student has both a cat and a dog?
\makeemptybox{\stretch{1}}
\newpage
\question[6] A pencil case contains 5 faulty and 7 working pens. A boy and then a girl each need to take a pen.
\begin{parts}
\part Determine the probability that two faulty pens are chosen.
\part Determine the probability that at least one faulty pen is chosen.
\part Given that exactly one faulty pen is chosen, what is the probability that the girl chose it?
\end{parts}
\makeemptybox{\stretch{1}}
\newpage
\end{questions}
\end{document}
有什么想法吗?我是 LaTeX 新手,所以任何建议都会有帮助!提前谢谢您。
答案1
使用mdframed
包装并配有 2 个计数器,可以在exam
包装中使用以下解决方案。
\documentclass[answers]{exam}
\makeatletter
\newcount\my@repeat@count
\newcommand{\myrepeat}[2]{%
\begingroup
\my@repeat@count=\z@
\@whilenum\my@repeat@count<#1\do{#2\advance\my@repeat@count\@ne}%
\endgroup
}
\makeatother
\newcount\myloopcounter
\newcommand{\repeatit}[2][10]{%
\myloopcounter0% initialize the loop counter
\loop\ifnum\myloopcounter < #1 % Test if the loop counter is < #1
#2%
\advance\myloopcounter by 1 %
\repeat % start again
}
\usepackage{mdframed}
\newenvironment{mymdf}
{\mdfsetup{
innertopmargin=15pt
}
\begin{mdframed}%
}
{\end{mdframed}}
\begin{document}
\begin{questions}
\question Approximate $\displaystyle \int_0^1 \sin x^2 \, dx$ within $.001$ of
its true value.
\begin{mymdf}
\repeatit[3]{\myrepeat{150}{.}\\} %3 row, 150 dot per row.
\end{mymdf}
\question A question with a long solution.
\begin{mymdf}
\repeatit[10]{\myrepeat{150}{.}\\} %10 row, 150 dot per row.
\end{mymdf}
\end{questions}
\end{document}
答案2
这是一个重新定义宏的解决方案\do@fillwithdottedlines
。宏现在在虚线周围打印一个边界框。部分内容从\do@emptybox
宏中重复使用。解决方案框首先打印垂直空白,然后打印虚线,然后再次打印垂直空白。垂直空白间距是硬编码的,因为\do@fillwithdottedlines
只接受一个参数(虚线的垂直间距)。出于某种我不清楚的原因,垂直空白间距必须是的倍数,\dottedlinefillheight
否则垂直规则将显示间隙。还有一个小的负 vskip 来获得不间断的垂直线(为什么我也不清楚)。我没有用其他解决方案框测试它。
\documentclass[a4paper,addpoints]{exam}
% Use next line to show the solutions
%\documentclass[a4paper,addpoints,answers]{exam}
\makeatletter
\setlength\dottedlinefillheight{.25in}
\newlength{\mylength}
\setlength{\mylength}{\textwidth}
\def\do@fillwithdottedlines#1{%
\hbox to \hsize{\hskip\@totalleftmargin \leaders\hrule\hfill}%
\begingroup
\advance \mylength by -\@totalleftmargin
\advance \mylength by -4em
\ifhmode
\par
\fi
\hrule height \z@
\nobreak
\setbox0=\hbox to \hsize{\hskip \@totalleftmargin \vrule \hskip 2em
\vrule height \dottedlinefillheight depth \z@ width \z@
\leavevmode\hbox to \mylength {\dotfill\hfil} \vrule}%
\setbox1=\hbox to \hsize{\hskip\@totalleftmargin
\vrule height\dottedlinefillheight \hfill \vrule}%
% We use \cleaders (rather than \leaders) so that a given
% vertical space will always produce the same number of lines
% no matter where on the page it happens to start:
\cleaders \copy1 \vskip 1\dottedlinefillheight%
\vskip -\minboxheight%
\vskip -1.5pt % Dirty hack
\cleaders \copy0 \vskip #1%
\vskip -\minboxheight%
\vskip -1.5pt % Dirty hack
\cleaders \copy1 \vskip 4\dottedlinefillheight%
\hbox to \hsize{\hskip\@totalleftmargin \leaders\hrule\hfill}%
\endgroup
}% \do@fillwithdottedlines
\qformat{\textbf{Question \thequestion{}} (\totalpoints \@pointname) \hfill}
\makeatother
\begin{document}
\begin{questions}
\question[10]
Calculate $1+1$.
\begin{solutionordottedlines}[2in]
2
\end{solutionordottedlines}
\question[10] Please give the answer to the ultimate question of life, the universe, and everything.
\begin{solutionordottedlines}[1.4in]
42
\end{solutionordottedlines}
\end{questions}
\end{document}