试卷答案空白处

试卷答案空白处

我制作了一个试卷模板,试卷上有问题和答案,定义了一个切换器,用于显示开/关答案。当切换器打开时,它会显示所有内容,否则只显示带有留下答案空间的问题以供写答案。

包裹彩色盒子用于设置答案位置的样式。包超链接有时也用于引用问题的编号。

但可能会出现问题,答案不能是“白色”(隐藏),并且当使用 amsmath 定理样式而不是 tcolorbox 时,带有链接的 autoref 也不能隐藏。

MWE 如下。

    \documentclass{article}

    \usepackage{lipsum}
    \def\exampleboxedtext{
         convenient way to generate a new theorem type. On the other hand, it enforces to use a titled
        \begin{equation}x^2 +y^2 =1\end{equation}
        a convenient way to generate a new theorem type. On the other hand, it
    }

    \usepackage[most]{tcolorbox}
    %------------------------
    \newcommand{\drtitt}{ %
        \node[anchor=north east,
        inner xsep=0pt,xshift=0.8em, %yshift=-0.2em,
        font=\bfseries] at (frame.north west) (tit) {\strut \fbox{ans}};
    }
    \newcommand{\drawTCBtopl}{
        \draw[line width=1.5pt,blue]([xshift=-2em,yshift=-0.2em]frame.north west)--([yshift=-0.2em]frame.north east); %top line
        }
    \newcommand{\drawTCBbotl}{
        \draw[line width=1.5pt,blue]([xshift=1.5em,yshift=0.3em]frame.south west)--([yshift=0.3em]frame.south east);
    }
    \newtcolorbox{examsolv}{ %
        empty,breakable,
        beforeafter skip=0pt,
        leftright skip=0pt,
        width=\dimexpr\linewidth+28pt\relax,
        text width=\linewidth-1mm,
        enlarge left by=-12pt,
        overlay unbroken ={\drtitt;\drawTCBtopl;\drawTCBbotl},
        overlay first={\drtitt; \drawTCBtopl},
        overlay middle={},
        overlay last={\drawTCBbotl},
        frame code={},interior code={},
        top=0pt,bottom=0pt,right=0pt
    }

    \newtoggle{showans} %etoolbox
    \togglefalse{showans}

    \newcommand{\yesnoans}[1]{\iftoggle{showans}{#1}{\color{white} #1}}
    \newenvironment{ansonoff}[1][0em]{ %
        \yesnoans
        \begingroup\begin{examsolv} %
        }{\end{examsolv} %
        \endgroup%
    }

    \usepackage{hyperref}

    \begin{document}

    \section{test}\label{sc:testsc}

    Switcher "showans" is off, but only the side text is hidden, the body still is showed. 

    \begin{ansonoff}
    \exampleboxedtext 
    that the ref with link like this \autoref{sc:testsc} cannot be hidden.
    this is a new problem! the typing text also cannot be hidden.
    \end{ansonoff}

    \lipsum[66]

    \begin{examsolv}
    \lipsum[66]
    \end{examsolv}

    \lipsum[66]

    \begin{enumerate}
    \item \lipsum[66]
    \begin{ansonoff}
        \lipsum[66-70]
    \end{ansonoff}
    \item \lipsum[66]
    \end{enumerate}

    \lipsum[66]
    \end{document}

答案1

您可以通过将颜色设置为白色来隐藏答案部分,但tcolorbox必须通过例如指定a 的颜色设置colupper。请注意,这不会影响链接的框架颜色:

\documentclass{article}

\usepackage{lipsum}
\def\exampleboxedtext{
     convenient way to generate a new theorem type. On the other hand, it enforces to use a titled
    \begin{equation}x^2 +y^2 =1\end{equation}
    a convenient way to generate a new theorem type. On the other hand, it
}

\usepackage[most]{tcolorbox}
%------------------------
\newcommand{\drtitt}{ %
    \node[anchor=north east,
    inner xsep=0pt,xshift=0.8em, %yshift=-0.2em,
    font=\bfseries] at (frame.north west) (tit) {\strut \fbox{ans}};
}
\newcommand{\drawTCBtopl}{
    \draw[line width=1.5pt,blue]([xshift=-2em,yshift=-0.2em]frame.north west)--([yshift=-0.2em]frame.north east); %top line
    }
\newcommand{\drawTCBbotl}{
    \draw[line width=1.5pt,blue]([xshift=1.5em,yshift=0.3em]frame.south west)--([yshift=0.3em]frame.south east);
}
\newtcolorbox{examsolv}{%
    empty,breakable,
    beforeafter skip=0pt,
    leftright skip=0pt,
    width=\dimexpr\linewidth+28pt\relax,
    text width=\linewidth-1mm,
    enlarge left by=-12pt,
    overlay unbroken ={\drtitt;\drawTCBtopl;\drawTCBbotl},
    overlay first={\drtitt; \drawTCBtopl},
    overlay middle={},
    overlay last={\drawTCBbotl},
    frame code={},interior code={},
    top=0pt,bottom=0pt,right=0pt
}

\newtoggle{showans} %etoolbox
\togglefalse{showans}

\newcommand{\yesnoans}[1]{\iftoggle{showans}{#1}{\color{white} #1}}

\newenvironment{ansonoff}{%
  \iftoggle{showans}{}{\color{white}\tcbset{colupper=white}}% <------------ Edited 
  \begin{examsolv}%
  }{\end{examsolv}%
}

\usepackage{hyperref}

\begin{document}

\section{test}\label{sc:testsc}

Switcher "showans" is off, but only the side text is hidden, the body still is showed.

\begin{ansonoff}
\exampleboxedtext
that the ref with link like this \autoref{sc:testsc} cannot be hidden.
this is a new problem! the typing text also cannot be hidden.
\end{ansonoff}

\lipsum[66]

\begin{examsolv}
\lipsum[66]
\end{examsolv}

\lipsum[66]

\begin{enumerate}
\item \lipsum[66]
\begin{ansonoff}
    \lipsum[66-70]
\end{ansonoff}
\item \lipsum[66]
\end{enumerate}

\lipsum[66]
\end{document}

在此处输入图片描述

将颜色设置为白色的另一种方法是将内容放入 的下部tcolorbox。 下部可以用 隐藏lowerbox=invisible。 这将删除完整的内容:

\documentclass{article}

\usepackage{lipsum}
\def\exampleboxedtext{
     convenient way to generate a new theorem type. On the other hand, it enforces to use a titled
    \begin{equation}x^2 +y^2 =1\end{equation}
    a convenient way to generate a new theorem type. On the other hand, it
}

\usepackage[most]{tcolorbox}
%------------------------
\newcommand{\drtitt}{ %
    \node[anchor=north east,
    inner xsep=0pt,xshift=0.8em, %yshift=-0.2em,
    font=\bfseries] at (frame.north west) (tit) {\strut \fbox{ans}};
}
\newcommand{\drawTCBtopl}{
    \draw[line width=1.5pt,blue]([xshift=-2em,yshift=-0.2em]frame.north west)--([yshift=-0.2em]frame.north east); %top line
    }
\newcommand{\drawTCBbotl}{
    \draw[line width=1.5pt,blue]([xshift=1.5em,yshift=0.3em]frame.south west)--([yshift=0.3em]frame.south east);
}
\newtcolorbox{examsolv}{%
    empty,breakable,
    beforeafter skip=0pt,
    leftright skip=0pt,
    width=\dimexpr\linewidth+28pt\relax,
    text width=\linewidth-1mm,
    enlarge left by=-12pt,
    overlay unbroken ={\drtitt;\drawTCBtopl;\drawTCBbotl},
    overlay first={\drtitt; \drawTCBtopl},
    overlay middle={},
    overlay last={\drawTCBbotl},
    frame code={},interior code={},
    top=0pt,bottom=0pt,right=0pt,
    middle=0mm,% unorthodox, but boxsep has a positive value <------------ Edited 
}

\newtoggle{showans} %etoolbox
\togglefalse{showans}

\newcommand{\yesnoans}[1]{\iftoggle{showans}{#1}{\color{white} #1}}

\newenvironment{ansonoff}{%
  \iftoggle{showans}{}{\color{white}\tcbset{lowerbox=invisible}}% <------------ Edited 
  \begin{examsolv}\tcblower%
  }{\end{examsolv}%
}

\usepackage{hyperref}

\begin{document}

\section{test}\label{sc:testsc}

Switcher "showans" is off, but only the side text is hidden, the body still is showed.

\begin{ansonoff}
\exampleboxedtext
that the ref with link like this \autoref{sc:testsc} cannot be hidden.
this is a new problem! the typing text also cannot be hidden.
\end{ansonoff}

\lipsum[66]

\begin{examsolv}
\lipsum[66]
\end{examsolv}

\lipsum[66]

\begin{enumerate}
\item \lipsum[66]
\begin{ansonoff}
    \lipsum[66-70]
\end{ansonoff}
\item \lipsum[66]
\end{enumerate}

\lipsum[66]
\end{document}

在此处输入图片描述

相关内容