2010-04-26 73 views

回答

1

tex.stackexchange给出的答案是:

\documentclass{article} 
\usepackage{listings} 
\renewcommand{\figurename}{Listing} 
        % replace figurename with the text that should preceed the caption 
\begin{document} 

\begin{figure}[thp] % the figure provides the caption 
\centering   % which should be centered 
\caption{Ausgabe des C-Programms} 
\begin{tabular}{c} % the tabular makes the listing as small as possible and centers it 
\begin{lstlisting}[label={gtt_c_ausgabe}] 
printf("Your code goes here.\n"); 
\end{lstlisting} 
\end{tabular} 
\end{figure} 

\end{document} 

...这仍然让我疑惑:

周围使用的代码框架,例如使用\lstset{frame=single,frameround=tttt},将框架方式放在右边。这怎么可以避免?

renewcommand位做什么?

0

我没有为上市包装在我的头顶上一个答案,但你可以尝试以下方法:

\framebox[.9\linewidth]{\parbox{.85\linewidth}{\tt Hello World\\Second line}} 

产生一箱为90%宽度为文本宽度的85%。

如果你想它为中心,你只是把\centering\tt命令前:

\framebox[.9\linewidth]{\parbox{.85\linewidth}{\centering \tt Hello World\\Second line}} 

如果你喜欢盒没有边框,简单地改变到\makebox(并保持论据因为他们的立场) 。