我製作了一個試卷模板,試卷包含問題和答案,定義了一個切換器來顯示開/關答案。當切換器打開時,它給出所有內容,否則僅給出帶有留下答案空間用於編寫答案的問題。
包裹顏色盒用於設定答案位置的樣式。包裹超引用有時也用於引用問題的編號。
但可能會出現問題,答案不能是「白色」(隱藏),當使用 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
您可以將顏色設為白色來隱藏答案部分,但 a 的顏色設定tcolorbox
必須由 eg 指定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}