我已逐字逐句地显示了一小段代码,我该如何为该逐字逐句添加注释/标题?

我已逐字逐句地显示了一小段代码,我该如何为该逐字逐句添加注释/标题?

我正在为工作中使用的工具编写一些文档,并且我添加了一些代码,这些代码带有注释来解释特定行的用途,如果我将其保留在逐字记录中(我确信这本身就是不好的做法),则此注释会从页面中消失。我的问题是,如何将其包含在逐字记录附近,并明确表明它与逐字记录有关,而不是与特定行有关?

\begin{verbatim}
*** Settings ***
Documentation     A test suite with a single test for valid login.  

Resource          AdminResource.txt
\end{verbatim}
\caption{The textit{Documentation} is the description that will be shown in the reports generated by RF and at run time when this test suite is running.}

答案1

这可能是也可能不是您想要的。在这里,我将逐字逐句放在一个框结构中(这意味着它不能跨越页面边界)。然后,我将\stackinset“标题”嵌入到相关区域的框上。

\documentclass{article}
\usepackage{verbatimbox,stackengine,xcolor}
\begin{document}
\begin{verbbox}
*** Settings ***
Documentation     A test suite with a single test for valid login.  

Resource          AdminResource.txt
\end{verbbox}
\stackinset{c}{}{t}{-.1cm}{\textcolor{red}{\sffamily\tiny\parbox{2.2in}{
 The \textit{Documentation} is the description that will be shown in the 
reports generated by RF and at run time when this test suite is running.}}}{\theverbbox}
\end{document}

在此处输入图片描述

这里使用\scriptsizeinset,而不是\tiny

\documentclass{article}
\usepackage{verbatimbox,stackengine,xcolor}
\begin{document}
\begin{verbbox}
*** Settings ***
Documentation     A test suite with a single test for valid login.  

Resource          AdminResource.txt
\end{verbbox}
\stackinset{r}{}{t}{-.2cm}{\textcolor{red}{\sffamily\scriptsize\parbox{3.5in}{
 The \textit{Documentation} is the description that will be shown in the 
reports generated by RF and at run time when this test suite is running.}}}{\theverbbox}
\end{document}

在此处输入图片描述

最后,我在这里将它呈现为看起来像一个正常的“标题”。

\documentclass{article}
\usepackage{verbatimbox,stackengine,lipsum}
\begin{document}
\lipsum[4]

\bigskip\begin{verbbox}
*** Settings ***
Documentation     A test suite with a single test for valid login.  

Resource          AdminResource.txt
\end{verbbox}
{\centering\stackon[12pt]{\footnotesize\parbox{\textwidth}{
 The \textit{Documentation} is the description that will be shown in the 
reports generated by RF and at run time when this test suite is running.}}{\theverbbox}%
  \par}\bigskip

\lipsum[4]
\end{document}

在此处输入图片描述

相关内容