删除列表下的难看空间

删除列表下的难看空间

以下代码:

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}


\usepackage{listings}

\lstset{ 
    backgroundcolor=\color{gray!10},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
    %basicstyle=\footnotesize,        % the size of the fonts that are used for the code
    breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
    breaklines=true,                 % sets automatic line breaking
    captionpos=b,                    % sets the caption-position to bottom
    commentstyle=\color{cyan},    % comment style
    escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
    extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
    keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
    keywordstyle=\color{darkblue},       % keyword style
    language=bash,       
    % numbers=left,             % the language of the code
    otherkeywords={xxx},
    numbersep=5pt,                   % how far the line-numbers are from the code
    showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
    showstringspaces=false,          % underline spaces within strings only
    showtabs=false,                  % show tabs within strings adding particular underscores
    stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
    stringstyle=\color{red},     % string literal style
    tabsize=2,                     % sets default tabsize to 2 spaces
    title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title
}
\begin{document}
\sffamily


  \begin{lstlisting}[language=bash,caption={xxx}]
    ubuntu@kubernetesmaster:~$ sudo apt get install
        \end{lstlisting}
\end{document}    

给我 : 输出

我怎样才能去除命令下的难看的灰色?

谢谢您的帮助

答案1

好吧,只需删除列表中第二行的一些空白即可:

\begin{lstlisting}[language=bash,caption={xxx}]
  ubuntu@kubernetesmaster:~$ sudo apt get install
\end{lstlisting}

经过完整校正的 mwe

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tikz}
\usepackage[many]{tcolorbox}
\usepackage{graphicx}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}


\usepackage{listings}

\lstset{ 
    backgroundcolor=\color{gray!10},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
    %basicstyle=\footnotesize,        % the size of the fonts that are used for the code
    breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
    breaklines=true,                 % sets automatic line breaking
    captionpos=b,                    % sets the caption-position to bottom
    commentstyle=\color{cyan},    % comment style
    escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
    extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
    keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
    keywordstyle=\color{darkblue},       % keyword style
    language=bash,       
    % numbers=left,             % the language of the code
    otherkeywords={xxx},
    numbersep=5pt,                   % how far the line-numbers are from the code
    showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
    showstringspaces=false,          % underline spaces within strings only
    showtabs=false,                  % show tabs within strings adding particular underscores
    stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered
    stringstyle=\color{red},     % string literal style
    tabsize=2,                     % sets default tabsize to 2 spaces
    title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title
}


\begin{document}
\sffamily

\begin{lstlisting}[language=bash,caption={xxx}]
  ubuntu@kubernetesmaster:~$ sudo apt get install
\end{lstlisting}
\end{document}

得到结果:

结果

相关内容