2010-05-08 84 views
2

我有一個包含計算機輸出作爲文本的逐字環境。本文由兩部分組成,每部分由一條空行與另一部分分開。乳膠電腦輸出段

段數及其內容是已知的,所以我不需要解析文本,但段之間的界線非常重要(因爲它爲「文本」提供了語義)。

每段都由多行組成。我怎樣才能在每個片段中心的左側寫(1)和(2)?

示例輸出:

 hello world 
(1)  out there 
     how are you? 

     I am 
     fine 
(2)  thanks 
     and 
     you? 

中的數字(1)和(2)不能在環境內,它們必須是外面,並在左邊,而不是作爲marginpar。

我懷疑這歸結爲將一個\ box {}或其他東西放在單詞「out」和「thanks」之前,並將它們向左移動一個負值。但我不知道如何實現這一點。

+0

您是否試圖將內容解析爲確定兩個部分,還是有可能有2個獨立的'逐字'部分?後者是一個更容易的問題。 – Geoff 2010-05-08 16:11:33

+0

改編它...我更喜歡反映文本語義的解決方案。由於這兩部分合在一起,它們應該保存在一個單一的環境中。然而,「在中心的左側書寫(X)」具有更高的優先級。 – Flavius 2010-05-08 16:16:51

回答

0

我已經成功地做到這一點我想要的方式和仍然保持了單逐字環境的語義是這樣的:

\usepackage{fancyvrb} 
\makeatletter 
\newcommand{\nl}[1]{\hbox to\[email protected]{% 
    \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} 
1

也許使用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}