![如何重置铸造代码中的行号?](https://linux22.com/image/414265/%E5%A6%82%E4%BD%95%E9%87%8D%E7%BD%AE%E9%93%B8%E9%80%A0%E4%BB%A3%E7%A0%81%E4%B8%AD%E7%9A%84%E8%A1%8C%E5%8F%B7%EF%BC%9F.png)
我在 minted 包中有一部分代码:
\begin{minted}[
frame=single,
numbersep = 1pt,
breaklines=true,
framesep=1mm,
baselinestretch=1,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos
]{java}
package test.multiple_interactions;
public class MainActivity extends Activity
{static{System.loadLibrary("threadLeak"); //"libthreadLeak.so"}
public static native void send(String data);
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tel = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = tel.getDeviceId();//source
String[] arr = new String[10];
arr[1] = imei;
send(arr);}}
\end{minted}
答案1
根据您的(不完整)示例,主要发生以下变化:
- 选项
escapeinside=||
已添加到minted
环境中 - 代码片段
|\setcounter{FancyVerbLine}{1}|
附加在 Java 代码行之后protected void onCreate(Bundle savedInstanceState){
。这FancyVerbLine
是行号中使用的计数器。
注意:这可能会破坏其他行号minted
选项。
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{minted}
\begin{document}
\begin{minted}[
frame=single,
numbersep = 1pt,
breaklines=true,
framesep=1mm,
baselinestretch=1,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos,
escapeinside=||
]{java}
package test.multiple_interactions;
public class MainActivity extends Activity
{static{System.loadLibrary("threadLeak"); //"libthreadLeak.so"}
public static native void send(String data);
protected void onCreate(Bundle savedInstanceState){|\setcounter{FancyVerbLine}{1}|
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TelephonyManager tel = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = tel.getDeviceId();//source
String[] arr = new String[10];
arr[1] = imei;
send(arr);}}
\end{minted}
\end{document}