在圖中列出換行時,如何刪除標題的多餘空白?

在圖中列出換行時,如何刪除標題的多餘空白?

我想包裹listing在一個人物裡面。但是當我這樣做時,其標題之間有足夠的空白。在圖中列出換行時,如何刪除圖標題的額外空白?

我有以下程式碼,起源

\expandafter\def\csname [email protected]\endcsname{}
\documentclass[10pt,journal,compsoc]{IEEEtran}
\PassOptionsToPackage{table}{xcolor}
\ifCLASSOPTIONcompsoc\usepackage[nocompress]{cite}
\else
    \usepackage{cite}
\fi
\ifCLASSINFOpdf\else\fi
\hyphenation{op-tical net-works semi-conduc-tor}
\usepackage[english]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{listings, xcolor}

\begin{document}
\section{Introduction}
hello world hello world hello world hello world
\begin{figure}[htp]
        \lstinputlisting[frame=tlrb, rulecolor=\color{black}]{hello.sol}
        \caption{hello world.}
\end{figure}
hello world hello world hello world hello world
\end{document}

你好.sol:

function hello() public returns (bool) {
    uint256 amount = 100
    return amount * 100
    return true;
}

輸出:

在此輸入影像描述

在這裡您可以看到標題的字體較小,標題的頂部和底部產生了大量空白。可以刪除那些嗎?

當我裡面有標題時,listing如果我可以替換Listing它,Figure它對我有用。

答案1

您的 MWE 不應依賴外部文件。如果可能,請提供可以複製貼上的獨立代碼。

然而,一個可能的解決方案是使用 的標題功能listings,而不是依賴圖形。刪除figure環境以及\caption命令,然後:

\lstinputlisting[caption={hello world.}, captionpos=b, frame=tlrb, rulecolor=\color{black}]{hello.sol}

相關內容