我创建了一个包含一些子图的图形,现在我想将它们的标题设置在顶部(仅在此单个图形中)并删除字母编号,如 (a) 和 (b)。我该怎么做?
以下是代码:
\documentclass{article}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\subfloat[Caption 1]{%
\includegraphics[width=0.5\linewidth]{figures/subfigure1.png}}
\hfill
\subfloat[Caption 2]{%
\includegraphics[width=0.5\linewidth]{figures/subfigure2.png}}
\caption{}
\label{fig1}
\end{figure}
\end{document}
答案1
请尝试以下操作:
\documentclass[draft]{article}
\usepackage{caption}
\usepackage[caption=false]{subfig} % <---
\usepackage{graphicx}
\begin{document}
\begin{figure}[ht] % <---
\captionsetup[subfigure]{labelformat=empty, % <---
position = top} % <---
\setkeys{Gin}{width=0.45\linewidth}
\centering
\subfloat[Caption 1]{%
\includegraphics{figures/subfigure1.png}}
\hfill
\subfloat[Caption 2]{%
\includegraphics{figures/subfigure2.png}}
\caption{}
\label{fig1}
\end{figure}
\end{document}
或者使用subcaption
包:
\documentclass[draft]{article}
\usepackage{subcaption} % <---
\usepackage{graphicx}
\begin{document}
\begin{figure}[ht] % <---
\captionsetup[sub]{labelformat=empty, % <---
position = top} % <---
\setkeys{Gin}{width=0.45\linewidth}
\centering
\subfloat[Caption 1]{%
\includegraphics{figures/subfigure1.png}}
\hfill
\subfloat[Caption 2]{%
\includegraphics{figures/subfigure2.png}}
\caption{}
\label{fig1}
\end{figure}
\end{document}
答案2
不要使用\subfloat
。这假设图像具有相同的高度。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htp]
\begin{tabular}[b]{@{}c@{}}
Caption 1 \\[1ex]
\includegraphics[width=0.5\columnwidth]{example-image-a}
\end{tabular}%<---
\begin{tabular}[b]{@{}c@{}}
Caption 2 \\[1ex]
\includegraphics[width=0.5\columnwidth]{example-image-b}
\end{tabular}
\caption{This is the caption}
\label{fig1}
\end{figure}
\end{document}