我有一张图片,想放入 tcolorbox,但图像太大而突出。
代码:
\documentclass{report}
\usepackage{geometry}
\usepackage{float}
\usepackage[italian]{babel}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usepackage{varwidth}
\usepackage{wrapfig}
\tcbset{enhanced,colback=cyan!5!white,colframe=cyan!75!black,fonttitle=\bfseries}
\begin{document}
\begin{tcolorbox}[every float=\centering, drop shadow, title=Esempio: misura della carica elettrica]
\begin{wrapfigure}{r}{0.5\textwidth}
\begin{center}
\includegraphics[width=0.48\textwidth]{fig1}
\end{center}
\label{fig:fig1}
\caption{Misura della carica elettrica}
\end{wrapfigure}
[Some text]
\end{tcolorbox}
\end{document}
结果:
我希望盒子能适合这个数字我该怎么办?谢谢!
答案1
使用两个minipage
s 并加载capt-of
包通过命令写入标题\captionof
\documentclass[demo]{report}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{float}
\usepackage[italian]{babel}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usepackage{varwidth}
\usepackage{capt-of}
\tcbset{enhanced,colback=cyan!5!white,colframe=cyan!75!black,fonttitle=\bfseries}
\begin{document}
\begin{tcolorbox}[every float=\centering, drop shadow, title=Esempio: misura della carica elettrica]
\begin{minipage}[t]{0.5\linewidth}
\vspace*{0pt}
\blindtext
\end{minipage}\hfill%
\begin{minipage}[t]{0.4\linewidth}
\vspace*{0pt}
\includegraphics[height=0.6\textheight,width=\linewidth]{fig1}
\captionof{figure}{Misura della carica elettrica}\label{fig:fig1}
\end{minipage}
\end{tcolorbox}
\end{document}
答案2
tcolorbox
这样做的方法是添加sidebyside,sidebyside align=top,lower separated=false
选项,tcolorbox
而不需要minipage
s。
\documentclass[demo]{report}
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{float}
\usepackage[italian]{babel}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usepackage{varwidth}
\usepackage{capt-of}
\usepackage[export]{adjustbox}
\tcbset{enhanced,colback=cyan!5!white,colframe=cyan!75!black,fonttitle=\bfseries}
\begin{document}
\begin{tcolorbox}[drop shadow, title=Esempio: misura della carica elettrica,sidebyside,sidebyside align=top,lower separated=false]
\blindtext
\tcblower
\includegraphics[height=0.6\textheight,width=\linewidth,valign=t]{fig1}
\captionof{figure}{Misura della carica elettrica}\label{fig:fig1}
\end{tcolorbox}
\end{document}
sidebyside align=top
您可以通过采用top
、center
(默认)和值的对齐方式来更改bottom
。