1

I have a lstlisting defined as follow

\begin{lstlisting}[language=bash,frame=single]
Offset(P)  Local Address             Remote Address            Pid
---------- ------------------------- ------------------------- ---
0x01e6a9f0 192.168.0.176:1176        212.150.164.203:80        888
0x01ec57c0 192.168.0.176:1189        192.168.0.1:9393          1244
0x01ed4270 192.168.0.176:2869        192.168.0.1:30379         1244
0x01eef808 192.168.0.176:2869        192.168.0.1:30380         4
0x01ffa7f8 0.0.0.0:0                 80.206.204.129:0          0
0x02041108 127.0.0.1:1168            127.0.0.1:1169            888
0x0225a448 192.168.0.176:1172        66.249.91.104:80          888
0x0226ac58 127.0.0.1:1169            127.0.0.1:1168            888
0x0227ac58 192.168.0.176:1171        66.249.90.104:80          888
0x02308890 192.168.0.176:1178        212.150.164.203:80        1752
0x02323008 192.168.0.176:1184        193.104.22.71:80          880
0x02410440 192.168.0.176:1185        193.104.22.71:80          880
\end{lstlisting}

I want to highlight certain lines so I have tried doing it like this:

\begin{lstlisting}[language=bash,escapeinside={<@}{@>},frame=single]
Offset(P)  Local Address             Remote Address            Pid
---------- ------------------------- ------------------------- ---
<@\colorbox{yellow}{0x01e6a9f0 192.168.0.176:1176        212.150.164.203:80        888}@>
0x01ec57c0 192.168.0.176:1189        192.168.0.1:9393          1244
0x01ed4270 192.168.0.176:2869        192.168.0.1:30379         1244
0x01eef808 192.168.0.176:2869        192.168.0.1:30380         4
0x01ffa7f8 0.0.0.0:0                 80.206.204.129:0          0
0x02041108 127.0.0.1:1168            127.0.0.1:1169            888
0x0225a448 192.168.0.176:1172        66.249.91.104:80          888
0x0226ac58 127.0.0.1:1169            127.0.0.1:1168            888
0x0227ac58 192.168.0.176:1171        66.249.90.104:80          888
0x02308890 192.168.0.176:1178        212.150.164.203:80        1752
0x02323008 192.168.0.176:1184        193.104.22.71:80          880
0x02410440 192.168.0.176:1185        193.104.22.71:80          880
\end{lstlisting}

But the highlighted line loses the previous formatting. I'm not sure how to achieve what I want?

1 Answer 1

1

You can cheat a bit by using three listings, and setting a background color for the middle one. Some adjustments are needed for the vertical margin using aboveskip and belowskip. The frame can be drawn separately with the framed package.

MWE:

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{framed}
\begin{document}
\begin{framed}
\scriptsize
\begin{lstlisting}[belowskip=0pt]
Offset(P)  Local Address             Remote Address            Pid
---------- ------------------------- ------------------------- ---
\end{lstlisting}
\begin{lstlisting}[backgroundcolor=\color{yellow},aboveskip=0pt,belowskip=0pt]
0x01e6a9f0 192.168.0.176:1176        212.150.164.203:80        888+
\end{lstlisting}
\begin{lstlisting}[aboveskip=0pt]
0x01ec57c0 192.168.0.176:1189        192.168.0.1:9393          1244
0x01ed4270 192.168.0.176:2869        192.168.0.1:30379         1244
0x01eef808 192.168.0.176:2869        192.168.0.1:30380         4
0x01ffa7f8 0.0.0.0:0                 80.206.204.129:0          0
0x02041108 127.0.0.1:1168            127.0.0.1:1169            888
0x0225a448 192.168.0.176:1172        66.249.91.104:80          888
0x0226ac58 127.0.0.1:1169            127.0.0.1:1168            888
0x0227ac58 192.168.0.176:1171        66.249.90.104:80          888
0x02308890 192.168.0.176:1178        212.150.164.203:80        1752
0x02323008 192.168.0.176:1184        193.104.22.71:80          880
0x02410440 192.168.0.176:1185        193.104.22.71:80          880
\end{lstlisting}
\end{framed}
\end{document}

Result:

enter image description here

1
  • This will work perfectly. Thanks
    – LTWood
    Nov 27, 2020 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.