lstinputlisting を正しく配置できません

lstinputlisting を正しく配置できません

ドキュメントに次のコードがあります:

\begin{figure}
    \center
    \includegraphics[scale=0.5]{images/image.jpg}
    \caption{image}
\end{figure}

The content of file.sh :
\begin{figure}
    \lstinputlisting[language=Bash,caption={mycaption}]{file.sh}
\end{figure}
Blablabla

ソースコードはテキストの後に置かれますかくかくしかじかそして、1 ページにあります。このテキストには、古典的なテキスト、セクションが含まれています。画像の直後に配置する必要があります。さらに、ソース コードはページの最後でカットされており、コードの半分が欠落しています... ログは次のとおりです。

<images/image.jpg, id=122, 442.65375pt x 492.84125pt>
File: images/image.jpg Graphic file (type jpg)
<use images/image.jpg>
Package pdftex.def Info: images/image.jpg used on input line 292.
(pdftex.def) Requested size: 221.32632pt x 246.42001pt.
(/usr/share/texlive/texmf-dist/tex/latex/listings/lstlang1.sty
File: lstlang1.sty 2015/06/04 1.6 listings language file
)
(/usr/share/texlive/texmf-dist/tex/latex/listings/lstlang1.sty
File: lstlang1.sty 2015/06/04 1.6 listings language file
)
Package hyperref Info: bookmark level for unknown lstlisting defaults to 0 on i
nput line 298.
LaTeX Font Info: Try loading font information for T1+cmtt on input line 298.
(/usr/share/texlive/texmf-dist/tex/latex/base/t1cmtt.fd
File: t1cmtt.fd 2014/09/29 v2.5h Standard LaTeX font definitions
)
(./file.sh)
LaTeX Warning: Float too large for page by 705.87885pt on input line 299.
[9]

私は気が狂いそうです。助けていただけると幸いです。

答え1

LaTeX が image-listing-Blablabla の順序を厳格に維持する必要がある場合は、環境を使用しないでくださいfigure。figure 環境にラップするすべてのものは、TeX が最適と判断する場所に移動する傾向があります。さらに、環境の内容はfigureページ間で分割されません。

ここに画像の説明を入力してください

\documentclass{article}
\usepackage{caption}% For the \captionof command, to be used outside of figures
\usepackage{graphicx}
\usepackage{listings}
\begin{document}
\begin{center}
    \includegraphics[scale=0.5]{example-image}
    \captionof{figure}{image}
\end{center}

The content of file.sh :
    \lstinputlisting[language=Bash,caption={mycaption}]{file.sh}
Blablabla
\end{document}

関連情報