我怎样才能在 tbox 里面使用 subcaptionbox?
我在 tbox 外部和内部输入了相同的代码,但 tbox 内部没有出现任何图像,并且出现了一条错误消息,如下图所示
------------------------- 代码是 -----------------------------
\documentclass[12pt,a4paper]{article}
\documentclass[12pt,a4paper,draft]{article}
\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[x11names,table]{xcolor}
\usepackage{eurosym}
\usepackage{datetime}
\settimeformat{ampmtime}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\usepackage{graphicx,subcaption}
\usepackage{tcolorbox}
\usepackage[spanish]{cleveref} %para crear referencias
% poner las dos siguientes líneas despues de begin- document % Type the next two lines after begin-document
\renewcommand{\tablename}{Tabla}
\crefname{table}{tabla}{tablas}
\begin{document}
The first 3 letters are in \cref{de-dos-en-dos}
\begin{figure}[h!]
\centering
\subcaptionbox{A\label{example-image-a.jpg}}
{\includegraphics[width=.24\linewidth]{example-image-a.jpg}}
%
%
\subcaptionbox{B\label{example-image-b.jpg}}
{\includegraphics[width=.24\linewidth]{example-image-b.jpg}}
%
%
\subcaptionbox{C\label{example-image-c.jpg}}
{\includegraphics[width=.24\linewidth]{example-image-c.jpg}}
%{\includegraphics[width=.31\linewidth]{ES-P-todo-0_01-m9.eps}}
\vspace{-0.25cm}
\caption{The first 3 letters of alphabet.}\label{de-dos-en-dos}
\end{figure}
\textbf{Question}
\begin{itemize}
\item What's the letter in the middle?
\end{itemize}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,title=\large{In the next lines I'm trying to insert the same in a box, using \emph{tcolorbox} package.}]
\tcblower
The first 3 letters are in \cref{de-dos-en-dos}
\begin{figure}[h!]
\centering
\subcaptionbox{A\label{example-image-a.jpg}}
{\includegraphics[width=.24\linewidth]{example-image-a.jpg}}
%
%
\subcaptionbox{B\label{example-image-b.jpg}}
{\includegraphics[width=.24\linewidth]{example-image-b.jpg}}
%
%
\subcaptionbox{C\label{example-image-c.jpg}}
{\includegraphics[width=.24\linewidth]{example-image-c.jpg}}
%{\includegraphics[width=.31\linewidth]{ES-P-todo-0_01-m9.eps}}
\vspace{-0.25cm}
\caption{The first 3 letters of alphabet.}\label{de-dos-en-dos}
\end{figure}
\textbf{Question}
\begin{itemize}
\item What's the letter in the middle?
\end{itemize}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
答案1
您不能将浮动环境放入figure
或 中minipage
。tcolorbox
但您可以使用\captionof
来\caption
将标题文本(带编号)放入minipage
或中tcolorbox
。不幸的是,\subcaptionbox
这里不能使用,必须用 minipages 等替换。
\documentclass[12pt,a4paper,draft]{article}
\usepackage{mwe}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[x11names,table]{xcolor}
\usepackage{eurosym}
\usepackage{datetime}
\settimeformat{ampmtime}
\usepackage{hyperref}
\hypersetup{colorlinks=true, urlcolor=blue}
\usepackage{graphicx,subcaption}
\usepackage{tcolorbox}
\usepackage[spanish]{cleveref} %para crear referencias
% poner las dos siguientes líneas despues de begin- document % Type the next two lines after begin-document
\renewcommand{\tablename}{Tabla}
\crefname{table}{tabla}{tablas}
\begin{document}
\begin{tcolorbox}[colback=gray!5!white,colframe=gray!75!black,
title=Using captionof]
The first 3 letters are in \cref{de-dos-en-dos}
\begin{center}%
\setcounter{subfigure}{0}%
%
\begin{minipage}{.24\linewidth}
\includegraphics[width=\linewidth]{example-image-a.jpg}%
\captionof{subfigure}{A}\label{example-image-a.jpg}%
\end{minipage}
%
\begin{minipage}{.24\linewidth}
\includegraphics[width=\linewidth]{example-image-b.jpg}%
\captionof{subfigure}{B}\label{example-image-b.jpg}%
\end{minipage}
%
\begin{minipage}{.24\linewidth}
\includegraphics[width=\linewidth]{example-image-c.jpg}%
\captionof{subfigure}{C}\label{example-image-c.jpg}%
\end{minipage}
\vspace{-0.25cm}
\captionof{figure}{The first 3 letters of alphabet.}\label{de-dos-en-dos}
\end{center}
\textbf{Question}
\begin{itemize}
\item What's the letter in the middle?
\end{itemize}
\end{tcolorbox}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}