如何重新顯示 tcolorbox 環境

如何重新顯示 tcolorbox 環境

\newtcolorbox我使用、自動編號和正確工作的目錄條目以及所有內容創建了一個新環境。各個項目準確地出現在章節中應有的位置。我想要的是在章節結尾或部分結尾或附錄或其他內容中再次顯示所有這些項目。我不需要另一個目錄;我想再次在一個大集合中顯示實際的環境項目,以及它們在文字主體中出現的方式。我沒有運氣找到這個問題的答案,所以任何建議將不勝感激。

答案1

recording功能tcolorbox簡化了內容的重新顯示。有一些方法可以使用recording,我這裡只介紹一種:

  1. 定義一個tcolorbox環境,​​例如displaythis用於首次顯示內容並將內容儲存到名為 的檔案中\jobname.display\thetcbcounter,該檔案擴展為等 \jobname.display1\jobname.display2
  2. record={\string\redisplaythis[#1]{\jobname.display\thetcbcounter}} 
    

    在環境的選項清單中displaythis,指示tcolorbox寫入\redisplaythis{#1}{\jobname.display\thetcbcounter}記錄檔。

  3. 定義一個總計tcolorbox reddisplaythis,它使用強制參數來載入已儲存的內容。 ( 的\NewTotalTColorBox優點是,也可以指定框的內容,與 相反tcolorbox

  4. \tcbstartrecording[myenvironments.env]在要保存的第一個環境之前和\tcbstoprecording最後一個環境之後使用。

  5. \tcbinputrecords[myenvironments.env]最後申請重新顯示。


\documentclass{book}

\usepackage[most]{tcolorbox}


\usepackage{blindtext}

\makeatletter

\NewTColorBox[auto counter,list type=section,list inside=red]{displaythis}{O{}}{%
  enhanced, 
  sharp corners, 
  title={My nice Environment \thetcbcounter},
  saveto={\jobname.display\thetcbcounter},
  record={\string\redisplaythis[#1]{\jobname.display\thetcbcounter}},
  #1,
}

\NewTotalTColorBox[auto counter]{\redisplaythis}{O{}m}{
  enhanced, 
  sharp corners, 
  title={My nice Environment (again) \thetcbcounter},
  #1
}{\input{#2}}
\makeatother

\begin{document}

\tcbstartrecording[myenvironments.env]
\tcblistof{red}{List of environments}


\begin{displaythis}
\blindtext 
\end{displaythis}


\begin{displaythis}[colback=white!60!yellow]
\blindtext[2]
\end{displaythis}
\tcbstoprecording

\tcbinputrecords[myenvironments.env]

\end{document}

在此輸入影像描述

相關內容