\subfloat
我有 2 张细图像。我使用from包将它们放入图形中subfig
。每个图像的子标题具有相同的图形宽度。我尝试通过创建环境来解决这个问题tabular
,但没有成功。我如何修改子标题以使其更宽,例如在这种情况下为线宽的一半?
\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{array}
\usepackage{subfig}
\begin{document}
\begin{figure}[htb]
\centering
\subfloat[This is a subcaption longer than 2 cm]{%
\includegraphics[width=2cm]{example-image-a}
\label{subfig:Tomadas-de-Pressao-PF4sub}
}
\quad
\subfloat[This is a subcaption longer than 2 cm]{%
\includegraphics[width=2cm]{example-image-b}
\label{fig:Tomadas-de-Pressao-PF5sub}
}
\caption{Short Caption}
\end{figure}
\begin{figure}[htb]
\centering
\begin{tabular}{*2{>{\centering\arraybackslash}m{0.5\linewidth}}}
\subfloat[This is a subcaption longer than 2 cm]{%
\includegraphics[width=2cm]{example-image-a}
}&%
\subfloat[This is a subcaption longer than 2 cm]{%
\includegraphics[width=2cm]{example-image-b}
}
\end{tabular}
\caption{Short Caption}
\end{figure}
\end{document}
答案1
肮脏的伎俩:
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}[htb]
\centering
\subfloat[This is a subcaption longer than 2 cm
\label{subfig:Tomadas-de-Pressao-PF4sub}]{%
\qquad % <--- added
\includegraphics[width=2cm]{example-image-a}
\qquad % <--- added
}
\hfil
\subfloat[This is a subcaption longer than 2 cm
\label{fig:Tomadas-de-Pressao-PF5sub}]{%
\qquad % <--- added
\includegraphics[width=2cm]{example-image-b}
\qquad % <--- added
}
\caption{Short Caption}
\end{figure}
\end{document}
然而,出现了一个问题:有什么原因不增加图像的宽度吗?
附录:更优雅的解决方案是使用subfigure
来自subcation
包的环境:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htb]
\centering
\begin{subfigure}[b]{0.3\linewidth}
\centering
\includegraphics[width=2cm]{example-image-a}
\caption{This is a subcaption longer than 2 cm}
\label{subfig:Tomadas-de-Pressao-PF4sub}
\end{subfigure}
\hfil
\begin{subfigure}[b]{0.3\linewidth}
\centering
\includegraphics[width=2cm]{example-image-b}
\caption{This is a subcaption longer than 2 cm}
\label{subfig:Tomadas-de-Pressao-PF5sub}
\end{subfigure}
\caption{Short Caption}
\end{figure}
\end{document}
结果与以前几乎相同。
答案2
我建议您从使用subfig
包切换到使用subcaption
包,因为后者提供了很多选项来定制subfigure
环境的各个方面。每个subfigure
的宽度设置为0.475\textwidth
,而图像的宽度设置为2cm
。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{subcaption,ragged2e}
\captionsetup[subfigure]{justification=RaggedRight}
\begin{document}
\hrule % just to illustrate width of textblock
\begin{figure}[htb]
\begin{subfigure}[t]{0.475\textwidth}
\centering
\includegraphics[width=2cm]{example-image-a}
\caption{This caption is considerably wider than the image}
\label{subfig:Tomadas-de-Pressao-PF4sub}
\end{subfigure}\hspace{\fill} % maximize separation between the subfigures
\begin{subfigure}[t]{0.475\textwidth}
\centering
\includegraphics[width=2cm]{example-image-b}
\caption{This caption is also much wider than the image}
\label{subfig:Tomadas-de-Pressao-PF5sub}
\end{subfigure}
\caption{Images and their associated captions}
\end{figure}
\end{document}