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

소스 코드는 텍스트 뒤에 위치합니다.블라블라블라그리고 한 페이지에. 이 텍스트에는 고전적인 텍스트인 섹션이 포함되어 있습니다. 이미지 바로 뒤에 배치해야 합니다. 게다가 소스 코드는 페이지 끝 부분이 잘려서 코드의 절반이 누락되었습니다... 로그는 다음과 같습니다.

<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가 엄격한 이미지 목록 작성-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}

관련 정보