我正在为我的学生写一份测试,我想在每个问题下画一个网格,让学生写下答案。目前它看起来像上面那样。理想情况下,我还希望在答案选项旁边和答案选项下面都有网格。(因此答案选项栏右侧的空白处将用网格填充)
我怎样才能用网格填充空白处?
以下是我的 MWE 代码:
\documentclass[a4paper,12pt,answers]{exam}
\usepackage[english,russian]{babel}
\usepackage[a4paper,top=2cm,bottom=2cm,left=1cm,right=1cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{titlesec}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{tabularx}
\setlength\columnsep{40pt}
\usepackage{amsmath}
\newcommand{\sectionbreak}{\clearpage}
\newcommand{\solgrid}{\begin{tikzpicture}
\draw[step=0.5cm,gray!30,very thin] (-10,0) grid (-3,4);
\end{tikzpicture}}
\pagestyle{fancy}
\fancyhead[C]{}
\begin{document}
\section*{Exam: 2024-03-18}
\markright{Exam: 2024-03-18}
\begin{multicols*}{2}
\begin{questions}
\question What number is 9 times smaller than $2\frac{1}{9}$ ?
\begin{choices}
\choice $\frac{1}{2}$
\choice $\frac{1}{4}$
\choice $\frac{1}{9}$
\choice $\frac{1}{36}$
\choice $\frac{2}{9}$
\end{choices}
\solgrid
\end{questions}
\end{multicols*}
\end{document}
答案1
\documentclass[a4paper, 12pt, answers]{exam}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc}
\newcommand{\solgrid}{
\begin{tikzpicture}[overlay, remember picture, very thin]
\pgfmathsetmacro{\gridx}{8.5}
\pgfmathsetmacro{\gridy}{6}
\pgfmathsetmacro{\gridinset}{3}
\clip let \p1=(pic cs:startgrid) in ({\gridinset cm-\pgflinewidth},\y1) -- (\gridx cm+1cm,\y1) -- +(0,-\gridy cm-1cm) -| (0,{0.3cm+\pgflinewidth}) -|cycle;
\draw[step=0.5cm, gray, yshift=-0.2cm] let \p1=(pic cs:startgrid) in (0,{int(\y1*1pt/1cm)*1cm}) grid +(\gridx cm, -\gridy cm);
\end{tikzpicture}
}
\renewcommand{\choiceshook}{\tikzmark{startgrid}}
\begin{document}
\section*{Exam: 2024-03-18}
\begin{questions}
\question What number is 9 times smaller than $2\frac{1}{9}$?
\begin{choices}
\choice $\frac{1}{2}$
\choice $\frac{1}{4}$
\choice $\frac{1}{9}$
\choice $\frac{1}{36}$
\choice $\frac{2}{9}$
\end{choices}
\solgrid
\end{questions}
\end{document}
编辑:现在每页还可以处理多个问题。在网格中制作自动网格并不容易exam
- 几乎所有东西都缺少样式。我使用了一个 hack,其中tikzmark
s 用计数器命名。使用grid
是有问题的,因为它需要整数值才能正确显示,并且choices
从不同的位置开始。-所以改为在循环中绘制线条。
\documentclass[a4paper, 12pt, answers]{exam}
\usepackage{tikz}
\usetikzlibrary{tikzmark, calc}
\newcounter{myn}
\newcommand{\solgrid}{
\begin{tikzpicture}[remember picture, overlay, very thin, gray]
\pgfmathsetmacro{\gridn}{17}
\pgfmathsetmacro{\gridm}{12}
\pgfmathsetmacro{\gridinset}{7}
\foreach \i in {0,...,\gridn}
\draw let \p1=(pic cs:startgrid\themyn) in ({0.5*\i},{\y1-(0.5*\gridm cm+0.3cm}) -- ({0.5*\i},{\i>=\gridinset?\y1-0.3cm:\y1-int((\y1-0.3cm)/0.5cm)*0.5cm-0.3cm});
\foreach \j in {0,...,\gridm}
\draw let \p1=(pic cs:startgrid\themyn) in ({\y1-0.3cm-0.5*\gridm cm+0.5*\j cm>0.5cm?0.5*\gridinset cm:0cm},{\y1-0.3cm-0.5*\gridm cm+0.5*\j cm}) -- ({0.5*\gridn cm},{\y1-0.3cm-0.5*\gridm cm+0.5*\j cm});
\end{tikzpicture}
}
\renewcommand{\choiceshook}{\stepcounter{myn}\tikzmark{startgrid\themyn}}
\begin{document}
\section*{Exam: 2024-03-18}
\begin{questions}
\question What number is 9 times smaller than $2\frac{1}{9}$?
\begin{choices}
\choice $\frac{1}{2}$
\choice $\frac{1}{4}$
\choice $\frac{1}{9}$
\choice $\frac{1}{36}$
\choice $\frac{2}{9}$
\end{choices}
\solgrid
\vspace{3cm}
\question What color is better than $2\frac{1}{9}$?
\begin{choices}
\choice red
\choice green
\end{choices}
\solgrid
\vspace{5cm}
\question What homeomorphisms is equivalent to $2\frac{1}{9}$?
\begin{choices}
\choice both
\choice green
\choice abricot
\choice hot
\choice yes
\choice true
\choice D.
\end{choices}
\solgrid
\end{questions}
\end{document}