![图形浮动内的标题](https://linux22.com/image/304889/%E5%9B%BE%E5%BD%A2%E6%B5%AE%E5%8A%A8%E5%86%85%E7%9A%84%E6%A0%87%E9%A2%98.png)
我希望在我的 LaTeX 中得到以下输出。
标题figure
应放在 的底部figure
。文本应plurred
与 一起opacity
。如何实现这一点?
我的 MWE 是:
\documentclass{book}
\usepackage{graphics}
\usepackage{caption}
\DeclareCaptionFormat{overlay}{\gdef\capoverlay{#1#2#3\par}}
\DeclareCaptionStyle{overlay}{format=overlay}
\begin{document}
\begin{figure*}
\includegraphics{example-image-a}
\caption{Many of the simple rexpressions in algebra can be thought of interms of the areas of rectangles.}
\end{figure*}
\end{document}
答案1
我建议如下:
这是使用以下tcolorbox
包实现的:
\documentclass{book}
\usepackage{graphics}
\usepackage{caption}
\DeclareCaptionFormat{overlay}{\gdef\capoverlay{#1#2#3\par}}
\DeclareCaptionStyle{overlay}{format=overlay}
\usepackage[skins]{tcolorbox}
\tcbset{
caption color/.store in=\captioncolor,
caption color=white}
\newcommand{\mygraphics}[3][]{%
\tcbincludegraphics[float*,every float=\centering,blanker,finish={%
\captionsetup{skip=0pt}%
\tcbsetmacrotowidthofnode\mywidth{interior}%
\node[above,fill=\captioncolor,fill opacity=0.5,text opacity=1,
outer sep=0mm,inner sep=2mm,text width=\mywidth-4mm]
at (interior.south) {\captionof{figure}{#3}};},
#1]{#2}%
}
\begin{document}
\mygraphics[caption color=blue!50]{Wing.png}
{Many of the simple expressions in algebra can be thought of
in terms of the areas of rectangles.}
\mygraphics[width=7cm]{example-image-a}
{Many of the simple expressions in algebra can be thought of
in terms of the areas of rectangles.}
\end{document}
我制作了一个宏\mygraphics
,它有两个必需参数:图像文件的名称和标题文本。此外,还可以给出一个键列表作为可选参数。键可以是任何tcolorbox
键。图像的制作方式float*
与 OP 给出的方式相同。
在此应用程序中,以下选项特别有趣:
width
设置图片的宽度(如示例代码所示)。默认为整个文本的宽度。caption color
设置标题的背景颜色(示例代码中显示)。默认为白色。floatplacement
设置浮动选项等htb
。
更新:
根据自然大小包含图像,hbox
可以添加选项。但是,许多图片可能会变得比文本宽度大。但是,要为底层\includegraphics
宏提供选项,您可以graphics options
在需要时使用。
以下代码将hbox
选项设置为默认值。另外,第二个示例显示了如何将scale=0.5
选项添加到图片中:
\documentclass{book}
\usepackage{graphics}
\usepackage{caption}
\DeclareCaptionFormat{overlay}{\gdef\capoverlay{#1#2#3\par}}
\DeclareCaptionStyle{overlay}{format=overlay}
\usepackage[skins]{tcolorbox}
\tcbset{
caption color/.store in=\captioncolor,
caption color=white}
\newcommand{\mygraphics}[3][]{%
\tcbincludegraphics[float*,every float=\centering,blanker,
hbox,% <--- the width is determined by the underlying '\includegraphics'
finish={%
\captionsetup{skip=0pt}%
\tcbsetmacrotowidthofnode\mywidth{interior}%
\node[above,fill=\captioncolor,fill opacity=0.5,text opacity=1,
outer sep=0mm,inner sep=2mm,text width=\mywidth-4mm]
at (interior.south) {\captionof{figure}{#3}};},
#1]{#2}%
}
\begin{document}
\mygraphics[caption color=blue!50]{Wing.png}
{Many of the simple expressions in algebra can be thought of
in terms of the areas of rectangles.}
\mygraphics[graphics options={scale=0.5}]{example-image-a}
{Many of the simple expressions in algebra can be thought of
in terms of the areas of rectangles.}
\end{document}