我正在使用列表来格式化 xeLaTeX 中的代码块。当我将此图片插入 Anki 的卡中时,插入的代码有多余的空白行。以下是我的 MWE:
\documentclass[tikz]{standalone}
\usepackage{tcolorbox,listings}
\usepackage{fontspec}
\setmonofont{Consolas}
\usepackage{color}
\usepackage{tikz}
\usepackage{framed}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{comments}{HTML}{868686}
\definecolor{darkred}{RGB}{139,0,0}
\definecolor{darkblue}{RGB}{0,0,139}
\definecolor{chartreuse}{RGB}{127,255,0}
\definecolor{drakgreen}{RGB}{0,128,0}
\definecolor{lightgray}{RGB}{238,239,240}
\lstset{
language=[LaTeX]Tex,
keywordstyle=\color{darkblue},
texcsstyle=*\color{blue},
basicstyle=\normalfont\ttfamily,
commentstyle=\color{comments}\ttfamily,
stringstyle=\rmfamily,
frame=lrtb,
%numbers=left,
numbers=none,
numberstyle=\scriptsize,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frameround=ftff,
frame=none,
captionpos=t,
belowcaptionskip=0em,
belowskip=0em,
literate=
*{\{}{{\textcolor{darkred}{\{}}}{1}
{\}}{{\textcolor{darkred}{\}}}}{1}
{[}{{\textcolor{darkred}{[}}}{1}
{]}{{\textcolor{darkred}{]}}}{1},
}
\lstdefinestyle{mystyle}{
language=[LaTeX]Tex,
extendedchars=true,
breaklines=true,
breakatwhitespace=true,
basicstyle=\ttfamily,
numbers=none,
keywordstyle=\color{darkblue},
keywordstyle=[2]\color{blue},
keywordstyle=[3]\color{darkblue},
keywordstyle=[4]\color{drakgreen},
alsoletter = {!},
keywords=[2]{definecolor,node,addplot},
keywords=[3]{usepackage},
keywords=[4]{begin,end,document,figure,figure*,axis}
}
\tcbuselibrary{listings,skins,breakable}
\newtcblisting{mycode}{
arc=0mm,
top=0mm,
bottom=0mm,
left=3mm,
right=0mm,
width=\textwidth,
boxrule=1pt,
colback=lightgray,
listing only,
%listing options={style=mystyle},
breakable
}
\begin{document}
\begin{mycode}
\begin{tikzpicture}
\filldraw [gray] (0,0) circle (2pt)
(1,1) circle (2pt)
(2,1) circle (2pt)
(2,0) circle (2pt);
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\end{mycode}
When executed, that is, run via pdflatex or via latex followed by dvips, the resulting will contain something that looks like this:
\end{document}
如何消除顶部的多余空白行?
注释掉这一行'listing only'之后,绘制了这段代码的图。
答案1
尝试:
\newtcblisting{mycode}{
arc=0mm,
top=0mm,
bottom=0mm,
left=3mm,
right=0mm,
width=\textwidth,
boxrule=1pt,
colback=lightgray,
% listing only,
listing options={style=mystyle},
breakable
}
选择listing only
就是问题所在。