代码之家  ›  专栏  ›  技术社区  ›  Flavius

乳胶计算机输出段

  •  2
  • Flavius  · 技术社区  · 15 年前

    我有一个包含计算机文本输出的逐字环境。此文本在语义上由两个部分组成,每个部分用空行分隔。

    节的数量及其内容是已知的,所以我不需要解析文本,但是节之间的行非常重要(因为它为“文本”提供了语义)。

    每个段由多条线组成。我怎样才能在每段中间的左手边写(1)和(2)?

    样品输出:

            hello world
    (1)     out there
            how are you?
    
            I am
            fine
    (2)     thanks
            and
            you?
    

    数字(1)和(2)不能在环境中,它们必须在外部,并且在左侧,不能作为保证金。

    我怀疑是在单词“out”和“thanks”前面放一个\框或什么东西,然后将它们向左移动一个负数。但我不知道如何做到这一点。

    2 回复  |  直到 15 年前
        1
  •  1
  •   unutbu    15 年前

    也许用 minipage :

    \renewcommand{\labelenumi}{(\arabic{enumi})}
    \begin{enumerate}
    \item
    \begin{minipage}[c]{1in}
    \begin{verbatim}
    hello world
    out there
    how are you?
    \end{verbatim}
    \end{minipage}
    
    \item
    \begin{minipage}[c]{1in}
    \begin{verbatim}
    I am
    fine
    thanks
    and
    you?
    \end{verbatim}
    \end{minipage}
    \end{enumerate}
    
        2
  •  0
  •   Flavius    15 年前

    我已经按我想要的方式做了,而且 仍然保留单个逐字环境的语义 这样地:

    \usepackage{fancyvrb}
    \makeatletter
    \newcommand{\nl}[1]{\hbox to\z@{%
        \hss (#1) \kern3pt}}
    \makeatother
    

    用法:

    \begin{Verbatim}[commandchars=\\\{\}]
    HTTP/1.1 200 OK
    Server: Apache/2.2.3 (Red Hat)
    Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT
    ETag: "b300b4-1b6-4059a80bfd280"            
    \nl{1}Accept-Ranges: bytes                        
    Content-Type: text/html; charset=UTF-8      
    Connection: Keep-Alive                      
    Date: Tue, 15 Dec 2009 11:52:46 GMT         
    Age: 2528                                   
    Content-Length: 438
    
    <HTML>
    <HEAD>
      <TITLE>Example Web Page</TITLE>
    </HEAD>                          
    <body>                           
    \nl{2}<p>You have reached this web page by typing &quot;example.com&quot;,
    &quot;example.net&quot;,                                            
      or &quot;example.org&quot; into your web browser.</p>             
    <p>These domain names are reserved for use in documentation and are not available 
      for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC   
      2606</a>, Section 3.</p>                                                        
    </BODY>                                                                           
    </HTML>
    \end{Verbatim}