LaTex下的listing,代码显示的高级操作,不加空格对齐,自动换行和外边框

近段时间使用latex往里面添加了一些代码,看着是很好看,但是copy出来的代码却一塌糊涂.到处都加满了空格,还不能自动换行.

S c i e n t i f i c computing f o r Lua .就像这样,但是在网上也没有找到相应的解决方法,最后只好到官方的指导文档上去找.官方文档链接:

https://mirrors.sjtug.sjtu.edu.cn/ctan/macros/latex/contrib/listings/listings.pdf

在里面看了好一段时间终于找到了解决的方法,就是在引入了宏包之后,添加如下设置.

\lstset{
  breaklines,%自动换行
  columns=flexible,%不随便添加空格,只在已经有空格的地方添加空格,
%如果想要添加空格使用fixed作为参数(这是默认的),如果坚决不添加空格使用fullflexible作为参数.
}

下面是参数的演示:

代码:

\begin{lstlisting}[breaklines=false,columns=fixed,frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}]
 ______             __   |  Torch7                                 
/_  __/__  ________/ /   |  Scientific computing for Lua.000000000000000000000000000000000000000         
 / / / _ \/ __/ __/ _ \  |                                           
/_/  \___/_/  \__/_//_/  |  https://github.com/torch   
                         |  http://torch.ch    

th>
\end{lstlisting}
\begin{lstlisting}[breaklines,columns=flexible,frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}]
  ______             __   |  Torch7                                 
 /_  __/__  ________/ /   |  Scientific computing for Lua.000000000000000000000000000000000000000         
  / / / _ \/ __/ __/ _ \  |                                           
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch   
                          |  http://torch.ch    
 
 th>
\end{lstlisting}
 \begin{lstlisting}[breaklines,columns=fullflexible,frameshape={RYRYNYYYY}{yny}{yny}{RYRYNYYYY}]
  ______             __   |  Torch7                                 
 /_  __/__  ________/ /   |  Scientific computing for Lua.         
  / / / _ \/ __/ __/ _ \  |                                           
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch   
                          |  http://torch.ch    
 
 th>
\end{lstlisting}

编译后的效果如下面所示

对比之后可以看到效果.

猜你喜欢

转载自blog.csdn.net/qq_36265860/article/details/82991345
今日推荐