约 300 字 预计阅读 1 分钟
- 排版一段代码用lstlisting环境(listing宏包)
- 将每一段代码用minipage环境包起来成为一个个box(注意设置每个minipage的宽度)
- 中间可以用\rule命令画线,用\hspace调整间距
- 若要给代码整体画个外框,可以将所有box一起放在framed环境(framed宏包)中
- 整体放入figure环境中,成为浮动体
示例代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| \begin{figure}[!htb]
\lstset{language=C,
numbers=left,
numbersep=3pt,
%frame=single,
tabsize=2,
xleftmargin=.05\textwidth,
%xrightmargin=.05\textwidth,
basicstyle=\footnotesize,
}
\begin{framed}
\begin{minipage}[b]{0.45\columnwidth}
\begin{lstlisting}
int callee(int x){
return x;
}
\end{lstlisting}
\end{minipage}
\rule{.1pt}{36mm}
\hspace{5pt}
\begin{minipage}[b]{0.3\columnwidth}
\begin{lstlisting}
int caller() {
return callee(5);
}
\end{lstlisting}
\end{minipage}
\end{framed}
\caption{An example program}
\end{figure}
|
相关内容