用线条填充下部,用于 tcolorbox

用线条填充下部,用于 tcolorbox

使用 tcolorbox 包为教科书制作练习,我使用该选项invisible为学生提供空间来写下他们的解决方案。

为此,我想让下部的空白处用水平线填充,让学生可以舒适地书写。对于较长的练习,当然也必须这样做,因为练习篇幅超过一页。我该怎么做呢?

请注意,我们可以使用选项获得网格help lines,但是此选项会生成网格而不是线条...所以我们可以添加一个类似的选项,只生成水平线而不是垂直线吗?

我给出一个 MWE:

\documentclass{article}

\usepackage{etoolbox}
\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter]{exercise}{m+O{}}{%
    enhanced,
    breakable,
    colframe=green!20!black,
    colback=yellow!10!white,
    coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=green!80!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \end{tcbclipinterior}},
    title={Exercise~ \thetcbcounter:},
    label={exercise:#1},
    attach title to upper=\quad,
    segmentation style={double=white,draw=green!20!black,double distance=1pt,solid},
    lowerbox=invisible,
    savelowerto=solutions/exercise-\thetcbcounter.tex,
    record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
    #2
}

\begin{document}
\pagestyle{empty}
\tcbstartrecording
\begin{exercise}{Ex1}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}

\tcblower
The derivative is:
\vspace*{5cm}   %% more space on solution for clarity
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\tcbstoprecording
\end{document}

及其汇编: 在此处输入图片描述

答案1

不是像、或 这样的lowerbox特殊元素,而是节点下方的空间,因此您可以使用switch 来判断相应的框片段是否包含下部。以下代码显示了使用内部条件的可能解决方案。顺便说一句,已经由 加载,您无需明确加载它。nodetitleinteriorframesegmentation\tcbsebmentstatetcbsegmentstateetoolboxetoolboxtcolorbox

\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}

\newtcolorbox{mybox}[1][]{
    enhanced,
    breakable,
    underlay unbroken and first={%
        \ifnumequal{\tcbsegmentstate}{1}{
            \begin{tcbclipinterior}
            \draw[help lines, ystep=\baselineskip, xstep=\linewidth] (segmentation.west) grid (frame.south east);
            \end{tcbclipinterior}
        }{} 
    },
    underlay middle and last={%
        \ifnumequal{\tcbsegmentstate}{1}{
            \begin{tcbclipinterior}
            \draw[help lines, ystep=\baselineskip, xstep=\linewidth] (segmentation.west) grid (frame.south east);
            \end{tcbclipinterior}
        }{\ifnumequal{\tcbsegmentstate}{2}{
            \begin{tcbclipinterior}
            \draw[help lines, ystep=\baselineskip, xstep=\linewidth] (frame.north west) grid (frame.south east);
            \end{tcbclipinterior}
            }{} 
        }
    },
    #1
}

\begin{document}
\begin{mybox}
\lipsum[1]
\tcblower
\lipsum[1]
\end{mybox}
\end{document}

在此处输入图片描述

相关内容