使用 tcolorbox 在下部添加空格

使用 tcolorbox 在下部添加空格

使用 tcolorbox 包为教科书制作练习,我使用 invisible 选项为学生提供书写解决方案的空间。实际上,学生需要更多的空间来书写解决方案,而不是将解决方案写下来。那么我该如何为选项添加垂直空间,比如 20mm invisible?此外,我该如何利用这个空间,在invisible短练习部分添加 10mm,在长练习部分添加 20mm?

我给出所用的程序:

\documentclass{book}

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

\NewTColorBox[auto counter,number within=chapter]{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);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \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:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\tcbstoprecording
\end{document}

答案1

不确定这个答案,但你总是可以height为整个盒子或add to natural height一些空间固定一个特定的。这个空间被分成顶部和底部,但你决定如何划分。如果所有都应该放在下部,请使用space to lower选项。更多信息请参见第节4.10 高度控制

\documentclass{book}

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

\NewTColorBox[auto counter,number within=chapter]{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);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \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:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\begin{exercise}{Ex2}[coltitle=cyan!80!black, add to natural height=2cm, space to lower]
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
\tcblower
The derivative is:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\tcbstoprecording
\end{document}

在此处输入图片描述

相关内容