如何在文章中使用任务环境创建的 \newpage 末尾添加正确答案键

如何在文章中使用任务环境创建的 \newpage 末尾添加正确答案键

我正在创建一个数学测试,这是我正在使用的文件。我喜欢这个文件,基本上我从不同的 latex 文件中复制了这个文件,一开始,我使用表格输入正确的键,这种方式太慢了,我犯了很多错误,我看到有些人可以通过在正确答案前添加 \CC 或使用 \correctchoice(在考试中)来解决这个问题,我不知道如何添加 \renewenvironment。

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{answers}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage{xpatch}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{multicol}

\newcommand{\ds}{\displaystyle}

\usepackage{tasks}
\setlength{\columnsep}{0.1cm}
\setlength{\columnseprule}{0.2pt}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=5mm,
 right=5mm,
 top=15mm,
 }



\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsmath,amssymb}
\usepackage{enumitem}
\usepackage{varwidth}


\usetikzlibrary{calc}

\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=.5mm, rounded corners, draw=#2, inner ysep=10pt, text width=#1, outer sep=0] (one) {\vspace*{15pt}\\\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white,anchor=north east,align=center, minimum height=20pt] (two) at (one.north east) {#3 \hspace*{.5mm}};
\path[fill=#2] 
    (one.north west|-two.west) --
    ($(two.west)+(-1.5cm,0)$) 
    to[out=0,in=180] (two.south west) --
    (two.south east) [rounded corners] --
    (one.north east) -- 
    (one.north west) [sharp corners] -- cycle;
\node[text=white,anchor=north east,align=center, minimum height=20pt, text height=2ex] (three) at (one.north east) {#3 \hspace*{.5mm}};
\end{tikzpicture} 
\end{figure}
}




\begin{document}


\begin{center}
\mybox{gray!70!black}{\Large{Test 1}}{
\hspace*{7.5cm}
Angles in parallel lines
}
\end{center}

\begin{multicols*}{2}
\begin{enumerate}
%%%%%%%%%%%%%Q1%%%%%%%%%%%%%
\item If the ratio of two supplementary angles is $\dfrac{4}{11}$, what is the measure of small angle?
\begin{tasks}[counter-format = {(tsk[A])},label-offset = {0.8em},item-indent={-0.1cm},label-format = {\bfseries}](5)
\task $36^\circ$
\task $44^\circ$
\task $48^\circ$
\task $52^\circ$
\task $60^\circ$
\end{tasks}\vspace*{1cm}
%C

%%%%%%%%%%%%%Q2%%%%%%%%%%%%%
\item 
\begin{tasks}[counter-format = {(tsk[A])},label-offset = {0.8em},item-indent={-0.1cm},label-format = {\bfseries}](4)
\task 
\task 
\task 
\task 
\end{tasks}

%%%%%%%%%%%%%Q3%%%%%%%%%%%%%
\item 
\begin{tasks}[counter-format = {(tsk[A])},label-offset = {0.8em},item-indent={-0.1cm},label-format = {\bfseries}](4)
\task 
\task 
\task 
\task 
\end{tasks}

\end{enumerate}
\end{multicols*}
\newpage



\end{document}

答案1

我建议

然后我们就可以在文档中进行干净的输入......

\begin{document}

\begin{examtitle}{Test 1}
  Angles in parallel lines
\end{examtitle}

\begin{multicols*}{2}
\begin{exercise}
  If the ratio of two supplementary angles is $\frac{4}{11}$, what is the
  measure of the small angle?
  \begin{choices}(5)
    \choice \ang{36}
    \choice \ang{44}
    \choice \answer{\ang{48}}
    \choice \ang{52}
    \choice \ang{60}
  \end{choices}
\end{exercise}
\begin{exercise}
  .
  .
  .
\end{document}

...并且仍然保持您想要的输出:

在此处输入图片描述


完整代码如下:

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}

\usepackage{parskip}
\usepackage{geometry}
\geometry{
  a4paper,
  total={170mm,257mm},
  left=5mm,
  right=5mm,
  top=15mm,
}

\usepackage{multicol}
\setlength{\columnsep}{0.1cm}
\setlength{\columnseprule}{0.2pt}

\usepackage[most]{tcolorbox}

\makeatletter
\newtcolorbox{examtitle}[2][]{
  halign=flush center,
  colframe=gray!70!black,
  fonttitle=\Large,
  enhanced, 
  breakable,
  colback=white,
  attach boxed title to top right={yshift=-2pt}, title={#2},
  boxed title size=standard,
  boxrule=0pt,
  boxed title style={
    sharp corners, 
    rounded corners=northeast, 
    colback=tcbcolframe, 
    boxrule=0pt},
  sharp corners=north,
  overlay unbroken={
    \path[fill=tcbcolback] 
      ([xshift=2pt]title.south west) 
      to[out=180, in=0] ([xshift=-1.5cm]title.west)--
      (title.west-|frame.west) |- 
      ([xshift=2pt]title.south west)--cycle;
    \path[fill=tcbcolframe] (title.south west) 
      to[out=180, in=0] ([xshift=-1.5cm]title.west)--
      (title.west-|frame.west)
      [rounded corners=\kvtcb@arc] |- 
      (title.north-|frame.north) 
      [sharp corners] -| (title.south west);
    \draw[line width=.5mm, rounded corners=\kvtcb@arc, 
      tcbcolframe] 
      (title.north east) rectangle 
      (frame.south west);
  }, 
  overlay first={
    \path[fill=tcbcolback] 
      ([xshift=2pt]title.south west) 
      to[out=180, in=0] ([xshift=-1.5cm]title.west)--
     (title.west-|frame.west) |- 
      ([xshift=2pt]title.south west)--cycle;
    \path[fill=tcbcolframe] (title.south west) 
      to[out=180, in=0] ([xshift=-1.5cm]title.west)--
      (title.west-|frame.west)
      [rounded corners=\kvtcb@arc] |- 
      (title.north-|frame.north) 
      [sharp corners] -| (title.south west);
    \draw[line width=.5mm, rounded corners=\kvtcb@arc, 
      tcbcolframe] 
      (frame.south west) |- (title.north) -| 
      (frame.south east);
  }, 
  overlay middle={
    \draw[line width=.5mm, tcbcolframe] 
    (frame.north west)--(frame.south west) 
    (frame.north east)--(frame.south east);
  },
  overlay last={
    \draw[line width=.5mm, rounded corners=\kvtcb@arc, 
      tcbcolframe] 
      (frame.north west) |- (frame.south) -|
      (frame.north east);
  }, 
  #1
}
\makeatother

\usepackage{siunitx}

\usepackage{xsim}
\xsimsetup{
  load-style = layouts ,
  exercise/template = minimal ,
  exercise/the-counter = \arabic{exercise}. ,
  exercise/end-hook = \vspace{\baselineskip}
}
  
\usepackage{tasks}
\NewTasksEnvironment[
  label = (\Alph*) ,
  label-format = \bfseries ,
  label-width = 21pt
]{choices}[\choice]

\DeclareExerciseProperty{answer}    
\newcommand*\answer[1]{%
  \SetExpandedExerciseProperty{answer}{ \thetask\ \unexpanded{#1}}%
 #1%
}

\newcommand*\getanswers{%
  \def\betweenanswers{\def\betweenanswers{\hspace{2em}}}%
  \ForEachUsedExerciseByID{%
    \betweenanswers##3\ExercisePropertyGet{##1}{##2}{answer}%
  }%
}

\usepackage{amsmath}
\usepackage{amsmath,amssymb}
\usepackage{enumitem}

\begin{document}

\begin{examtitle}{Test 1}
  Angles in parallel lines
\end{examtitle}

\begin{multicols*}{2}
\begin{exercise}
  If the ratio of two supplementary angles is $\frac{4}{11}$, what is the
  measure of the small angle?
    \begin{choices}(5)
      \choice \ang{36}
      \choice \ang{44}
      \choice \answer{\ang{48}}
      \choice \ang{52}
      \choice \ang{60}
    \end{choices}
  \end{exercise}
  \begin{exercise}
    Is this really a question?
    \begin{choices}(4)
      \choice \answer{yes}
      \choice no
      \choice maybe
      \choice no idea
    \end{choices}
  \end{exercise}
    \begin{exercise}
    This really is a question!
    \begin{choices}(4)
      \choice yes
      \choice \answer{no}
      \choice maybe
      \choice no idea
    \end{choices}
  \end{exercise}
  \subsection*{Answers}
  \getanswers
\end{multicols*}

\end{document}

相关内容