我正在尝试撰写一些有关格式化为非常古老的标准(ARINC 424)的数据的评论,其中每个记录都是 132 列的行,并且数据字段由它们占据的列来标识。
因此,我希望能够在 lstlisting 环境中除了对行进行编号之外,还能对列进行编号,但是在 listing 包文档中我找不到任何方法来执行此操作。
我认为将列表顶部的列号逆时针旋转 90 度打印出来会比较容易阅读。有人知道我该如何实现吗?
提前致谢。我包括了 MWE,但我认为它不是特别有用,因为我根本不知道如何处理这个问题。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=0.985in]{geometry} % weird margin so ARINC lines fit at 132 chars
\usepackage{xcolor}
\usepackage{listings} %for code snippets
\lstset{
tabsize=4,
numbers=left,
numberstyle=\ttfamily\color{gray},
frame = l,
basicstyle=\scriptsize\ttfamily,
breaklines=true,
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
}
\usepackage[scaled=0.85]{beramono} %better typewriter font
\usepackage[T1]{fontenc}
\begin{document}
\begin{lstlisting}[
float=hbt!,
caption=CIFP definition of the RNAV (GPS) Y RWY 13 approach procedure.,
label=lst:kacyiap
]
SUSAP KACYK6FR13-Y ACARYL 010CARYLK6PC0EE AR HF 12790060 + 02000 18000 A JS 090681310
SUSAP KACYK6FR13-Y AKOVEC 010KOVECK6PC0E A IF 18000 A JS 090691310
SUSAP KACYK6FR13-Y AKOVEC 020CARYLK6PC0EE B 010TF 03780060 + 02000 A JS 090701310
SUSAP KACYK6FR13-Y AWAGIR 010WAGIRK6PC0E A IF 18000 A JS 090711310
SUSAP KACYK6FR13-Y AWAGIR 020CARYLK6PC0EE B 010TF 21790060 + 02000 A JS 090721310
SUSAP KACYK6FR13-Y R 010CARYLK6PC0E I IF + 02000 18000 A JS 090731310
SUSAP KACYK6FR13-Y R 020MAYBNK6PC1E F 051TF 12790061 + 01600 A JS 090741310
SUSAP KACYK6FR13-Y R 020MAYBNK6PC2WALPV ALNAV/VNAV ALNAV JS 090751310
SUSAP KACYK6FR13-Y R 030RW13 K6PG0GY M 031TF 12790046 00133 -300 A JS 090761010
SUSAP KACYK6FR13-Y R 040 0 M CA 1279 + 00275 A JS 090771010
SUSAP KACYK6FR13-Y R 050JURADK6PC0E 010DF A JS 090781310
SUSAP KACYK6FR13-Y R 060RODDIK6PC0EY 010TF 0756 + 02000 A JS 090791310
SUSAP KACYK6FR13-Y R 070RODDIK6PC0EE R020HM 21820050 + 02000 A JS 090801310
\end{lstlisting}
\end{document}
答案1
一种方法可能是以 5 为步长在第一行上方写下列号。
这可以作为lstlisting
环境的一部分来完成,但是很难定制 - 例如不放置行号或框架,并以灰色打印列号。
另一种方法是使用两个列表环境,一个用于列号,一个用于实际代码。浮动环境使这有点棘手,但您可以将列号列表用作浮动列表,将实际代码用作非浮动列表。这不能保证两个列表保持在同一页上,因此您需要在最终文档中仔细检查这一点。两个列表上方和下方的间距也应使用belowskip
和进行调整aboveskip
。
梅威瑟:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=0.985in]{geometry} % weird margin so ARINC lines fit at 132 chars
\usepackage{xcolor}
\usepackage{listings} %for code snippets
\lstset{
tabsize=4,
numbers=left,
numberstyle=\ttfamily\color{gray},
frame = l,
basicstyle=\scriptsize\ttfamily,
breaklines=true,
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
}
\usepackage[scaled=0.85]{beramono} %better typewriter font
\usepackage[T1]{fontenc}
\begin{document}
\begin{lstlisting}[
float=hbt!,
caption=CIFP definition of the RNAV (GPS) Y RWY 13 approach procedure.,
label=lst:kacyiap,
frame=none,
numbers=none,
basicstyle=\scriptsize\ttfamily\color{gray},
belowskip=0pt,
]
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130
\end{lstlisting}
\begin{lstlisting}[aboveskip=-15pt]
SUSAP KACYK6FR13-Y ACARYL 010CARYLK6PC0EE AR HF 12790060 + 02000 18000 A JS 090681310
SUSAP KACYK6FR13-Y AKOVEC 010KOVECK6PC0E A IF 18000 A JS 090691310
SUSAP KACYK6FR13-Y AKOVEC 020CARYLK6PC0EE B 010TF 03780060 + 02000 A JS 090701310
SUSAP KACYK6FR13-Y AWAGIR 010WAGIRK6PC0E A IF 18000 A JS 090711310
SUSAP KACYK6FR13-Y AWAGIR 020CARYLK6PC0EE B 010TF 21790060 + 02000 A JS 090721310
SUSAP KACYK6FR13-Y R 010CARYLK6PC0E I IF + 02000 18000 A JS 090731310
SUSAP KACYK6FR13-Y R 020MAYBNK6PC1E F 051TF 12790061 + 01600 A JS 090741310
SUSAP KACYK6FR13-Y R 020MAYBNK6PC2WALPV ALNAV/VNAV ALNAV JS 090751310
SUSAP KACYK6FR13-Y R 030RW13 K6PG0GY M 031TF 12790046 00133 -300 A JS 090761010
SUSAP KACYK6FR13-Y R 040 0 M CA 1279 + 00275 A JS 090771010
SUSAP KACYK6FR13-Y R 050JURADK6PC0E 010DF A JS 090781310
SUSAP KACYK6FR13-Y R 060RODDIK6PC0EY 010TF 0756 + 02000 A JS 090791310
SUSAP KACYK6FR13-Y R 070RODDIK6PC0EE R020HM 21820050 + 02000 A JS 090801310
\end{lstlisting}
\end{document}
结果: