彩色十六进制转储

彩色十六进制转储

我想在文档中打印十六进制转储,其中我为某些特定字节着色。我尝试使用逃出内部然后做文字颜色在我的列表但这会改变文本的格式。字节需要保持对齐。

示例输出:

示例代码:

\lstset{escapeinside={<@}{@>}}
\begin{lstlisting}[language=none, basicstyle=\scriptsize]
01b0    00  00  00  00  00  00  00  00  78  56  34  12  <@\textcolor{blue}{00}@>  <@\textcolor{blue}{00}@>  00  01
01c0    <@\textcolor{blue}{01}@>    <@\textcolor{blue}{00}@>    <@\textcolor{blue}{83}@>   <@\textcolor{blue}{fe}@>     <@\textcolor{blue}{ff}@>    <@\textcolor{blue}{ff}@>    3f  00  00  00  41  29  54  02  00  fe
01d0    ff  ff  82  fe  ff  ff  80  29  54  02  fa  e7  1d  00  00  fe
01e0    ff  ff  83  fe  ff  ff  7a  11  72  02  fa  e7  1d  00  80  fe
01f0    ff  ff  05  fe  ff  ff  74  f9  8f  02  0c  83  6c  04  <@\textcolor{red}{55}@>     <@\textcolor{red}{aa}@>
\end{lstlisting}

有什么方法可以让我保留原来的字体样式吗?清单逃出内部
或者,还有更好的方法?

答案1

lstlisting为什么首先需要使用?一个简单的解决方案tabular是:

\documentclass{article}

\usepackage[]{color}

\begin{document}
\begingroup
\ttfamily
\scriptsize
\begin{tabular}{@{}*{17}c@{}}
  01b0 & 00 & 00 & 00 & 00 & 00 & 00 & 00 & 00 & 78 & 56 & 34 & 12 & \color{blue}{00} & \color{blue}{00} & 00 & 01 \\
  01c0 & \color{blue}{01} & \color{blue}{00} & \color{blue}{83} & \color{blue}{fe} & \color{blue}{ff} & \color{blue}{ff} & 3f & 00 & 00 & 00 & 41 & 29 & 54 & 02 & 00 & fe \\
  01d0 & ff & ff & 82 & fe & ff & ff & 80 & 29 & 54 & 02 & fa & e7 & 1d & 00 & 00 & fe \\
  01e0 & ff & ff & 83 & fe & ff & ff & 7a & 11 & 72 & 02 & fa & e7 & 1d & 00 & 80 & fe \\
  01f0 & ff & ff & 05 & fe & ff & ff & 74 & f9 & 8f & 02 & 0c & 83 & 6c & 04 & \color{red}{55} & \color{red}{aa} \\
\end{tabular}
\endgroup
\end{document}

在此处输入图片描述

相关内容