私は完全な初心者です。LaTeX についてはあまり知りません。画像の配置について助けが必要です。基本的に、6 つの図があり、それぞれ 2 つずつが横に並ぶサブ図にしたいと考えています。以下にコードを記載します。
\begin{figure}[h]
\centering
\begin{subfigure}[t][0.49\textwidth]
\centering
\includegraphics[width=0.49\textwidth]{pt 900/p900.png}
\caption{$p_T$ spectra of p at 900}
\label{fig:1-a}
\end{subfigure}
\hfill
\begin{subfigure}[t][0.49\textwidth]
\centering
\includegraphics[width=0.49\textwidth]{pt 900/pbar900.png}
\caption{$p_T$ spectra of pbar at 900 GeV}
\label{fig:1-b}
\end{subfigure}
\caption{$p_T$ spectra of identified charged particles at 900 GeV}
\label{fig:1}
\end{figure}
\end{document}
サブフィギュアを 6 回繰り返しました。問題は、まず第一に、希望する結果が得られないことです。第二に、サブフィギュアごとにこれら 2 つのエラーが発生します。
<to be read again>
\protect
l.34 \centering
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
<to be read again>
\protect
l.34 \centering
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
どうか誰か助けてください。あらゆることを試しましたが、解決できません。緊急に必要です。
追伸:私の前文
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}
\usepackage{hyperref}
答え1
おそらく、他のサブフロート関連パッケージの表記法や構文を混ぜているのでしょう。subcaption
subfigure
は、環境に似た環境を提供しsubcaptionblock
、1 つの必須引数を取ります。現在、垂直位置と幅の引数をオプションとして指定しており、これが問題の原因です。
代わりに以下を使用してください。
\documentclass{article}
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{0.49\linewidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{$p_T$ spectra of p at 900}
\label{fig:1-a}
\end{subfigure}
\hfill
\begin{subfigure}{0.49\textwidth}
\centering
\includegraphics[width=\linewidth]{example-image-b}
\caption{$p_T$ spectra of pbar at 900 GeV}
\label{fig:1-b}
\end{subfigure}
\caption{$p_T$ spectra of identified charged particles at 900 GeV}
\end{figure}
\end{document}
次の点に注意してください。
の単一の必須引数は、
subfigure
サブ図が配置されるボックスの幅を定義します (内部的には が使用されますsubcaptionblock
)。ブロックの幅を(たとえば に)設定すると、スケーリングに を
0.49\textwidth
使用するだけで、ブロックの幅全体が埋められます。width=\linewidth
\includegraphics
2 つのサブ図の間にスペースが必要なだけのようですので
\centering
、必要ありません\hfill
。