Latex:带有等宽字体的列表

标签 latex

这就是代码在 Xcode 中的样子。 xcode

这在我用 texlive 创建的列表中。

alt text

是的,我使用了 basicstyle=\ttfamily 。查看了列表手册后,我没有找到任何有关固定字体或等宽字体的信息。

重现示例

\documentclass[
  article,
  a4paper,
  a4wide,
  %draft,
  smallheadings
]{book}

% Packages below
\usepackage{graphicx}
\usepackage{verbatim} % used to display code
\usepackage{hyperref}
\usepackage{fullpage}
\usepackage[ansinew]{inputenc} % german umlauts
\usepackage[usenames,dvipsnames]{color}
\usepackage{float}
\usepackage{subfig}
\usepackage{tikz}
\usetikzlibrary{calc,through,backgrounds}
\usepackage{fancyvrb}
\usepackage{acronym}
\usepackage{amsthm} % Uuhhh yet another package
\VerbatimFootnotes % Required, otherwise verbatim does not work in footnotes!
\usepackage{listings}

\definecolor{Brown}{cmyk}{0,0.81,1,0.60}
\definecolor{OliveGreen}{cmyk}{0.64,0,0.95,0.40}
\definecolor{CadetBlue}{cmyk}{0.62,0.57,0.23,0}
\definecolor{lightlightgray}{gray}{0.9}

\begin{document}
\lstset{
language=C,                             % Code langugage
basicstyle=\ttfamily,                   % Code font, Examples: \footnotesize, \ttfamily
keywordstyle=\color{OliveGreen},        % Keywords font ('*' = uppercase)
commentstyle=\color{gray},              % Comments font
numbers=left,                           % Line nums position
numberstyle=\tiny,                      % Line-numbers fonts
stepnumber=1,                           % Step between two line-numbers
numbersep=5pt,                          % How far are line-numbers from code
backgroundcolor=\color{lightlightgray}, % Choose background color
frame=none,                             % A frame around the code
tabsize=2,                              % Default tab size
captionpos=b,                           % Caption-position = bottom
breaklines=true,                        % Automatic line breaking?
breakatwhitespace=false,                % Automatic breaks only at whitespace?
showspaces=false,                       % Dont make spaces visible
showtabs=false,                         % Dont make tabls visible
columns=flexible,                       % Column format
morekeywords={__global__, __device__},  % CUDA specific keywords
}

\begin{lstlisting}
    As[threadRow][threadCol] = A[
        threadCol + threadRow * Awidth   // Adress of the thread in the current block
        + i * BLOCK_SIZE                 // Pick a block further left for i+1
        + blockRow * BLOCK_SIZE * Awidth // for blockRow +1 go one blockRow down
    ];
\end{lstlisting}

\end{document}

最佳答案

问题出在 columns=flexible 选项上。删除它,它看起来就像你想要的样子。至少,如果您没有实际理由使用它。如果存在,则无法使您的代码片段看起来像 Xcode 中那样:)。

关于Latex:带有等宽字体的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2913141/

相关文章:

latex - 扩展matplotlib mathtext解析器

python-3.x - 在 python tabulate 中创建嵌套表

r - r-markdown 文档的在线编译器

减少 Rmd PDF 中 ggplot 和标题之间的空白

python - Sphinx LaTeX 标记限制

latex - 使用 LaTeX 编程源代码的字体

正则表达式编辑 latex 表

latex - Latex 表对齐的简单问题

r - Rmarkdown/Papaja 中的文本(不是语法)突出显示

r - 使用 memisc、xtable 等将自定义行添加到 LaTeX 输出的 R 回归结果表中。