带 lstlisting 包的 LaTeX 中的字符间距
我试图让我的代码片段看起来尽可能好,但到目前为止我在字符间距方面遇到了麻烦。以下是输出示例:
alt text http://grab.by/grabs/2bb230de7c088d007733f52b95a40363.png
小就是完美,所有大写字母的关键词看起来都很糟糕。这是我使用的设置
\lstset{basicstyle=\footnotesize, basewidth=0.5em}
如果我增加基本宽度,大写字母看起来不错,但我无法在一行中获得任何合适大小的代码行。以下示例不适合页面,我已经在其中添加了两个换行符: alt text http://grab.by/grabs/97ec29aa5a6811ce28bcd30bd389b52f.png
有谁知道我如何得到这个工作?使用 \ttfamily 可以解决问题,但是,我更喜欢保留字体。
谢谢。
I'm trying to get my code snippets to look as good as possible and so far I'm having troubles with the character spacing. Here is an example of the output:
alt text http://grab.by/grabs/2bb230de7c088d007733f52b95a40363.png
While the text in small is perfect, all the keywords that are in capital letters look terrible. Here are the settings I use
\lstset{basicstyle=\footnotesize, basewidth=0.5em}
If I increase the basewidth, the capital letters look good, but I can't get any decent sized line of code in one line. The following example does not fit in a page and I already put two line breaks in:
alt text http://grab.by/grabs/97ec29aa5a6811ce28bcd30bd389b52f.png
Does anyone have a clue how I can get this to work? Using \ttfamily does the trick, however, I'd prefer keeping the font.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您优先考虑美观,那么使用灵活的列是更好的选择:
If you prioritize looking nice, then using flexible colums is preferable:
您“显然”需要水平缩小大写字母。我不知道有什么方法可以在不实际编辑字体本身的情况下做到这一点。
但是,您可以将整个列表放入
\scalebox
中。\resizebox
(来自graphicx
包)。顺便说一句,您使用的字体似乎有点奇怪,因为小写字母之间的距离明显大于大写字母之间的距离。
You "obviously" need to scale the capital letters down horizontally. I do not know of a way to do this without actually editing the font itself.
However, you could put the entire listing into a
\scalebox
resp.\resizebox
(from thegraphicx
package).On a side note, the font you are using seems a bit strange, though, since the distance between small letters is significantly bigger than that between capital letters.