假设我有这样的代码:
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\textbf{Text I want centered} \\
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \\
{\centering \textbf{Text to be centered}} \\
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \\
{\centering \textbf{Center me}} \\
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \\
\end{figure}
\end{document}
我的目标是将文本置于每组三个数字的上方。第一个不起作用,因为我没有尝试将其居中。但是,我预计第二个和第三个会居中,因为我将它们放在{\centering }
代码片段中。有没有办法将它们居中?如果有更好的方法(例如副标题或其他内容),则不需要对文本进行编码。
答案1
据我了解,您的问题正在寻找以下解决方案:
其生成方式为:
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
\textbf{Text I want centered}
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}}
\textbf{Text to be centered}
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}}
\textbf{Center me}
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}} \hfill
\subfloat[Image]{\label{}\includegraphics[width=42mm]{example-grid-100x100pt}}
\end{figure}
\end{document}