如何收集 tcolorbox 的内容而不是标题?

如何收集 tcolorbox 的内容而不是标题?

我有一个问题/答案tcolorbox,我想这样,当我将它们收集到问题列表中时,它会打印上方框的内容而不是框的标题。

\documentclass{book}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{hyperref}


\NewTColorBox[auto counter,number within=section,list inside={questions}] {question}{+O{}}{ %
enhanced,colframe=red!20!black,colback=yellow!15!white,coltitle=red!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
\shade[inner color=red!50!yellow,outer color=yellow!10!white];
\end{tcbclipinterior}},
title={Question:},
label={questions@\thetcbcounter},
attach title to upper=\quad
}


\usepackage{xcolor}
    \colorlet{Mycolor1}{red!40!black}
\newcommand{\solution}{\tcblower \textbf{\textcolor{Mycolor1}  {Solution:}}\hphantom{so}}

\begin{document}
\chapter{foo}
\section{Some problems}
\tcblistof[\section*]{questions}{List of Questions}

\lipsum[1]
\begin{question}
the question
\solution
the solution
\end{question}

\lipsum[2]
\begin{question}
another question
\solution
its solution
\end{question}

\end{document}

有什么想法吗?我尝试使用

\NewEnviron{objectives}
 {%
  \addcontentsline{obj}{obj}{%
    \noexpand\unexpanded{\unexpanded\expandafter{\BODY}}%
  }%
 }

但我不知道如何将其调整为彩色框

答案1

作为 Christian,我不明白你想做什么,但借助list entry和辅助命令,你可以输入问题内容列表。它似乎甚至可以处理长行或断行。

\documentclass{book}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{hyperref}

\NewTColorBox[auto counter,number within=section,list inside={questions}]{question}{O{}}{ %
enhanced,colframe=red!20!black,colback=yellow!15!white,coltitle=red!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
\shade[inner color=red!50!yellow,outer color=yellow!10!white];
\end{tcbclipinterior}},
title={Question:},
label={questions@\thetcbcounter},
attach title to upper=\quad,
#1
}


\usepackage{xcolor}
    \colorlet{Mycolor1}{red!40!black}

\newcommand{\solution}{\tcblower \textbf{\textcolor{Mycolor1}  {Solution:}}\hphantom{so}}

\newcommand{\listquestion}[2]{%
    \begin{question}[list entry={#1}]
    #1
    \solution
    #2
    \end{question}}


\begin{document}
\chapter{foo}

\section{Some problems}

\tcblistof[\section*]{questions}{List of Questions}

Bla bla bla

\listquestion{this question is a very long question which needs more than one line to be typed}{the solution}

Bla bla bla

\listquestion{another question\\ with a second line}{its solution}

\end{document}

在此处输入图片描述

相关内容