
我想在代碼的頂部和底部有邊框。我嘗試將其設定lstset
如下:
\lstset{frame=topline|bottomline}
然而,它只是刪除了右側邊框並保持所有邊框完好無損。當我嘗試時:
\lstset{frame=topline}
它正確地保留了頂部邊框,刪除了所有其他邊框。
同樣,當我嘗試時:
\lstset{frame=bottomline}
它正確地保留了底部邊框,刪除了所有其他邊框。
我怎樣才能將兩者結合起來?
答案1
根據文檔,該frame
密鑰接受以下值:
none
,
leftline
,
topline
,
bottomline
,
lines
(頂部和底部),
single
對於單幀,
shadowbox
。
(請參閱文件版本 1.8d 第 18 頁的「2.7 佈局元素」部分listings
。)
為了獲得頂線和底線,您可以使用內建lines
鍵,如下所示:
\lstset{frame=lines}
除了前面提到的 7 種預定義樣式之外,您還可以使用t
、l
、r
和的組合來微調清單周圍的線條b
(用於單行)或使用大寫版本的雙行。
因此,列表上方和下方的一行將對應於:
\lstset{frame=tb}
答案2
根據手冊(第36頁)您必須使用單一字元指定多個選項:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{language=Pascal}
\begin{lstlisting}[frame=tb]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}
\end{document}