【问题标题】:LaTeX make only some listing use colour and not all (listings package) [closed]LaTeX 仅使某些列表使用颜色而不是全部(列表包)[关闭]
【发布时间】:2020-01-25 15:05:55
【问题描述】:

我使用以下代码为我在乳胶中创建的列表添加了颜色,

\usepackage{listings}% http://ctan.org/pkg/listings
\lstset{
  basicstyle=\ttfamily,
  mathescape
}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\usepackage[colorinlistoftodos]{todonotes}

\lstset{frame=tb,
  language=Python,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=3
}

这会将颜色应用于我创建的所有列表,我想创建一个不使用任何颜色的新列表,同时保留其他列表的颜色。

有人能告诉我该怎么做吗,或者是否有可能?

谢谢

【问题讨论】:

    标签: colors latex latex-environment


    【解决方案1】:

    提供给 \lstset 的所有命令都可以作为可选参数提供给特定列表。

    所以你可以这样做

    \begin{lstlisting}[keywordstyle=\color{black},
      commentstyle=\color{black},
      stringstyle=\color{black},
    ]
    < your program >
    

    所有其他参数保持不变,但您可以根据需要更改特定值。

    另一种方式,是定义样式。

    \lstdefinestyle{nocoloring}{
        keywordstyle=\color{black},
        commentstyle=\color{black},
        stringstyle=\color{black}
    }
    
    \begin{lstlisting}{style=nocoloring}
    < your program >
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多