如下图所示,列表与文本重叠。我定义了自己的列表“样式”。我认为这导致了问题。我该如何修复它?:)
代码:
\section{ New Section }
\begin{wrapfigure}[5]{r}{.5\textwidth}
\begin{lstlisting}[language=rust, caption=Test, label={lst:test}]
fn main(){
let a = 42;
let b = 32;
let c = 42;
let d = 32;
}
\end{lstlisting}
\end{wrapfigure}
hello hello hello hello hello hello hello hello ...
语言定义:
\lstdefinelanguage{rust}
{
columns=fullflexible,
keepspaces=true,
frame=single,
framesep=0pt,
framerule=0pt,
framexleftmargin=4pt,
framexrightmargin=4pt,
framextopmargin=5pt,
framexbottommargin=3pt,
xleftmargin=4pt,
xrightmargin=4pt,
backgroundcolor=\color{GrayCodeBlock},
basicstyle=\footnotesize\color{BlackText},
keywords={
true,false,
unsafe,async,await,move,
use,pub,crate,super,self,mod,
struct,enum,fn,const,static,let,mut,ref,type,impl,dyn,trait,where,as,
break,continue,if,else,while,for,loop,match,return,yield,in
},
keywordstyle=\color{PurpleKeyword},
ndkeywords={
bool,u8,u16,u32,u64,u128,i8,i16,i32,i64,i128,char,str,
Self,Option,Some,None,Result,Ok,Err,String,Box,Vec,Rc,Arc,Cell,RefCell,HashMap,BTreeMap,
macro_rules
},
ndkeywordstyle=\color{RedTypename},
comment=[l][\color{GrayComment}\slshape]{//},
morecomment=[s][\color{GrayComment}\slshape]{/*}{*/},
morecomment=[l][\color{GoldDocumentation}\slshape]{///},
morecomment=[s][\color{GoldDocumentation}\slshape]{/*!}{*/},
morecomment=[l][\color{GoldDocumentation}\slshape]{//!},
morecomment=[s][\color{RedTypename}]{\#![}{]},
morecomment=[s][\color{RedTypename}]{\#[}{]},
stringstyle=\color{GreenString},
string=[b]"
basicstyle=\footnotesize,
numbers=left,
stepnumber=1,
showstringspaces=false,
tabsize=1,
breaklines=true,
breakatwhitespace=false,
}
更新:
\documentclass[a4paper,12pt]{article}
问题与复制代码有关
列表周围的浮动文本有效,但替换\documentclass[letterpaper]{article}
会
\documentclass[a4paper,12pt]{article}
导致问题
全部代码:
\documentclass[a4paper,12pt]{article} % was \documentclass[letterpaper]{article}
\usepackage{listings}
\usepackage{blindtext}
\usepackage{wrapfig}
\begin{document}
\begin{wrapfigure}[5]{r}{.6\textwidth}
\begin{lstlisting}
public void Main (string[] args)
{
// here goes some code
// here goes some code
// here goes some code
// here goes some code
// here goes some code
}
\end{lstlisting}
\end{wrapfigure}
\blindtext
\end{document}
答案1
你使用了[5]
所以只有 5 行被剪掉,但你有 6 行代码和标题以及指定的顶部边距,所以没有机会适合,删除[5]
和 wrapfig 将根据需要剪切尽可能多的行