我得到的这个列表左侧有一个灰色的条,里面有行号。我不想让它显示在标题旁边。
这是我的代码:
\usepackage{listings}
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}
\newtcblisting[auto counter,number within=section]{cpp}[2][]{
title={Listing \thetcbcounter: #2},
coltitle=black,
colback=white,
boxrule=0pt,
arc=0pt,
outer arc=0pt,
top=0pt,
bottom=0pt,
colframe=white,
listing only,
left=15.5pt,
enhanced,
listing options={
basicstyle=\footnotesize\ttfamily,
keywordstyle=\color{blue}\ttfamily,
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily,
breaklines=true,
language=C++,
showstringspaces=false,
tabsize=2,
numbers=left
},
overlay={
\fill[gray!30]
([xshift=-3pt]frame.south west)
rectangle
([xshift=11.5pt]frame.north west);
}
}
它看起来像这样
答案1
xshift
您可以使用和yshift
或使用calc
tikzlibrary 通过在角标识符中添加坐标元组(此处frame.north west
和)来调整框覆盖的角frame.south west
。
梅威瑟:
\documentclass{article}
\usepackage{listings}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}
\tcbuselibrary{listings}
\newtcblisting[auto counter,number within=section]{cpp}[2][]{
title={Listing \thetcbcounter: #2},
coltitle=black,
colback=white,
boxrule=0pt,
arc=0pt,
outer arc=0pt,
top=0pt,
bottom=0pt,
colframe=white,
listing only,
left=15.5pt,
enhanced,
listing options={
basicstyle=\footnotesize\ttfamily,
keywordstyle=\color{blue}\ttfamily,
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily,
breaklines=true,
language=C++,
showstringspaces=false,
tabsize=2,
numbers=left
},
overlay={
\fill[gray!30]
([xshift=-3pt,yshift=8pt]frame.south west)
rectangle
($(frame.north west)+(0.5,-0.75)$);
}
}
\begin{document}
\begin{cpp}{iwconfig Aufruf}
root:~> iwconfig eth0
eth0 IEEE 802.11-bgn ESSID:off/any
Access Point: Not-Associated Bit Rate=0 kb/s
\end{cpp}
\end{document}
结果:
顺便问一下:当你关闭所有边框等时,为什么要使用 tcolorbox?一个简单的 lstlisting 可能就足够了。