在 LaTex 中,我使用 \verbatim 添加一段文本。但问题是,逐行文本不符合页面样式,如果文本较长,则会超出页面边界。结果如下:
如您所见,示例调用超出了边界。这就是我使用逐字的地方。以下是我设置逐字文本的代码,有人能告诉我如何解决这个问题吗?我将不胜感激。我有点急着要完成它。
% Used by @verbatim ... @endverbatim
\newenvironment{DoxyVerb}{%
\fontencoding{OT1}\fontfamily{cmr}\fontseries{b}\fontshape{n}\fontsize{10pt}{10}\selectfont%
\verbatim%
}{%
\endverbatim%
\normalsize%
}
答案1
\documentclass[dvipsnames,cmyk]{article}
\usepackage{listings,xcolor}
\lstset
{
breaklines=true,
tabsize=3,
showstringspaces=false
}
\lstdefinestyle{Common}
{
extendedchars=\true,
language={[Visual]Basic},
frame=single,
%===========================================================
framesep=3pt,%expand outward.
framerule=0.4pt,%expand outward.
xleftmargin=3.4pt,%make the frame fits in the text area.
xrightmargin=3.4pt,%make the frame fits in the text area.
%===========================================================
rulecolor=\color{Red}
}
\lstdefinestyle{A}
{
style=Common,
backgroundcolor=\color{Yellow!10},
basicstyle=\scriptsize\color{Black}\ttfamily,
keywordstyle=\color{Orange},
identifierstyle=\color{Cyan},
stringstyle=\color{Red},
commentstyle=\color{Green}
}
\lstdefinestyle{B}
{
style=Common,
backgroundcolor=\color{Black},
basicstyle=\scriptsize\color{White}\ttfamily,
keywordstyle=\color{Orange},
identifierstyle=\color{Cyan},
stringstyle=\color{Red},
commentstyle=\color{Green}
}
\begin{document}
\begin{description}
\item[Visual Basic] is a programming language from Microsoft.
\begin{lstlisting}[style=A]%please try style=B
Option Explicit
Sub Signal(strSignalfolge As String, Optional lngTakt As Long = 100)
'Prozedur erzeugt eine Serie von Warntönen.
'Die optionale Variable lngTakt gibt den Takt in Millisekunden vor (Standard: 100 ms)
'Das Muster kann über die String-Variable strSignalfolge beeinflusst werden:
' Stern (*) -> 1 Warnton
' Ziffern 1..9 -> 1..9 Takte Pause
' Leerzeichen -> 1 Sekunde Pause
' Minus (-) -> 1.5 Sekunden Pause
End Function
\end{lstlisting}
\item[Visual CSharp] is my favourite programming language.
\end{description}
\end{document}
答案2
逐字模式非常特殊,无法在其他宏或环境中使用(除了专门为此编写的逐字环境)。我建议使用逐字相关的包,例如listings
。它允许您定义自己的环境,包括字体更改和换行。它还支持许多不同语言的语法突出显示。
\documentclass{article}
% Recommended to get bold text typer font:
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{listings}
\lstnewenvironment{DoxyVerb}{%
\lstset{%
basicstyle={\fontencoding{OT1}\fontfamily{cmr}\fontseries{b}\fontshape{n}\fontsize{10pt}{10}\selectfont},
breaklines,
language=C,
}%
}{%
}
\usepackage{lipsum}% for dummy text
\begin{document}
\lipsum[1]
\begin{DoxyVerb}
uint16 someparameter;
someparameter_init_procedure_very_long_name = some stuff + even more ; // And also a comment afterwards
int random() {
return 4; // chosen by fair dice roll
}
\end{DoxyVerb}
\lipsum[2]
\end{document}