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}

 

编译后的效果如下面所示

对比之后可以看到效果.

 

  • 17
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值