完全初學者,需要數字的幫助

完全初學者,需要數字的幫助

我是一個完全的初學者。我對乳膠了解不多。我需要定位圖像的幫助。基本上,有 6 個數字,我希望它們是子圖,其中兩個並排。我將我的程式碼放在下面。

\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}

我已經重複了子圖的事情六次了。問題是我首先沒有得到想要的結果。其次,我對每個子圖都收到這兩個錯誤。

<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.)

請有人幫助我。我已經嘗試了一切,但似乎無法弄清楚。我迫切需要這個。
PS:我的序言

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{float}
\usepackage{hyperref}

答案1

您可能正在混合其他子浮點相關套件的符號/語法。使用時subcaption,它提供了一個subfigure與環境相似的環境subcaptionblock,並採用單一強制參數。您目前提供垂直位置和寬度參數作為可選,這是問題的原因。

請改用以下內容:

在此輸入影像描述

\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,它將填充區塊的整個寬度。

  • 看來您只想在兩個子圖之間有一個空格,所以不需要\centering,只需\hfill.

相關內容