如何使用 tcolorbox 保留圖形標題

如何使用 tcolorbox 保留圖形標題

在此輸入影像描述 如何將標題圖保留在 tcolorbox 內?我想將餅圖放入 tcb 中,但是當我刪除\begin{figure}[h]和時\end{figure},標題被刪除。有什麼解決辦法嗎?謝謝。

圖解:

 \begin{figure}[h]
 \centering 
 \begin{tikzpicture}
   \pie [polar]{10/Excellentes, 20/Bonnes, 30/Moyennes, 40/Mauvaises}
 \end{tikzpicture}
 \caption{ Présentation  }
 \label{fig: Question}
 \end{figure}

 \\

 \begin{tcolorbox}[colback=white]

 \centering 
 \begin{tikzpicture}
   \pie [polar]{10/Excellentes, 20/Bonnes, 30/Moyennes, 40/Mauvaises}
 \end{tikzpicture}
 \caption{ Présentation  ghjghjghjg }
 \label{fig: Qp}
 \end{tcolorbox}

答案1

歡迎!tcolorbox允許您使用浮點數,例如tcolorboxes 中的數字(或更準確地說,as 中的數字)。您需要tcolorbox為此定義一個。

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{pgf-pie}
\begin{document}
 \begin{figure}[h]
 \centering 
 \begin{tikzpicture}
   \pie [polar]{10/Excellentes, 20/Bonnes, 30/Moyennes, 40/Mauvaises}
 \end{tikzpicture}
 \caption{ Pr\'esentation  }
 \label{fig: Question}
 \end{figure}

% define a tcolorbox version of figures, see p. 115 of the manual
\newtcolorbox[blend into=figures]{myfigure}[2][]{float=htb,capture=hbox,
title={#2},every float=\centering,#1}


\begin{myfigure}[label={fig:Qp},% <- label goes here
    colback=white]{Another pr\'esentation.}% <- caption goes here
 \begin{tikzpicture}
   \pie [polar]{10/Excellentes, 20/Bonnes, 30/Moyennes, 40/Mauvaises}
 \end{tikzpicture}
 \end{myfigure}

As shown in figure~\ref{fig:Qp}, one can have floats in (or, more precisely, as)
\verb|tcolorbox|es.
\end{document}

在此輸入影像描述

另外,請考慮將來向我們提供以 開頭\documentclass和結尾的完整文檔\end{document},內容最少且可編譯。

相關內容