![如何使用子图将文本置于图中中央](https://linux22.com/image/394216/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%AD%90%E5%9B%BE%E5%B0%86%E6%96%87%E6%9C%AC%E7%BD%AE%E4%BA%8E%E5%9B%BE%E4%B8%AD%E4%B8%AD%E5%A4%AE.png)
假设我有这样的代码:
\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}