我正在使用 Beamer 准备演示文稿。我需要在某张幻灯片中打印大量逐字文本,还需要在其上绘制一些红色矩形。
最直接的方法是什么? 我正在为 fancyvrb 和 tikz 而苦苦挣扎。
\documentclass[pdf]{beamer}
\usepackage{semiverbatim}
\begin{document}
\newsavebox\myv
\begin{frame}[fragile]
\frametitle{IAEA phase-space file format}
\begin{lrbox}{\myv}\begin{minipage}{\textwidth}
\begin{semiverbatim}
$ xxd -b -l 100 ELEKTA_PRECISE_6mv_part1.IAEAphsp
0000000: 00000001 01101001 01010011 01001000 10111111 10100011 .iSH..
0000006: 11110110 10101101 11000000 01111110 00000100 10011110 ...~..
000000c: 11000000 11101011 10001011 10110101 10111110 01110011 .....s
0000012: 01110010 10100111 10111110 11001101 11001100 01001100 r....L
0000018: 00111101 00000100 00000000 00000000 00000000 01100111 =....g
000001e: 00000000 10000000 00000001 00000001 00100011 11011111 ....#.
0000024: 01101110 00111110 00000100 10110010 10000010 00111111 n>...?
000002a: 10110101 01000001 11010000 10111110 01101011 01111111 .A..k.
0000030: 00011111 00111101 10111011 00101111 01010000 10111100 .=./P.
0000036: 11001101 11001100 01001100 00111101 00000000 00000000 ..L=..
000003c: 00000000 00000000 01100111 00000000 10000000 00000001 ..g...
0000042: 00000001 01101000 10100000 11001110 00111111 01000010 .h..?B
0000048: 10011010 10101100 10111111 00000111 00010110 01100010 .....b
000004e: 01000000 01000010 00101010 01000011 10111101 11110111 @B*C..
0000054: 11101011 00000101 00111110 11001101 11001100 01001100 ..>..L
000005a: 00111101 00000000 00000000 00000000 00000000 01100111 =....g
0000060: 00000000 10000000 00000001 00000001 ....
$
\end{semiverbatim}
\end{frame}
\end{document}
这是我希望图像显示的方式(请注意红色矩形):
答案1
有一种可能性是:
\documentclass[pdf]{beamer}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\lstset{
basicstyle=\ttfamily\small,
columns=fullflexible,
escapeinside={/@}{@/}
}
\newcommand\DrawBox[2]{%
\begin{tikzpicture}[remember picture,overlay]
\draw[red]
([yshift=1.7ex,xshift=-2pt]pic cs:#1) rectangle ([yshift=-.25ex,xshift=2pt]pic cs:#2);
\end{tikzpicture}%
}
\begin{document}
\begin{frame}[fragile,shrink=15]
\frametitle{IAEA phase-space file format}
\DrawBox{starta}{enda}
\DrawBox{startb}{endb}
\DrawBox{startc}{endc}
\begin{lstlisting}
$ xxd -b -l 100 ELEKTA_PRECISE_6mv_part1.IAEAphsp
0000000: /@\tikzmark{starta}@/00000001 01101001 01010011 01001000 10111111 10100011 .iSH..
0000006: 11110110 10101101 11000000 01111110 00000100 10011110 ...~..
000000c: 11000000 11101011 10001011 10110101 10111110 01110011 .....s
0000012: 01110010 10100111 10111110 11001101 11001100 01001100 r....L
0000018: 00111101 00000100 00000000 00000000 00000000 01100111/@\tikzmark{enda}@/ =....g
000001e: /@\tikzmark{startb}@/00000000 10000000 00000001 00000001 00100011 11011111 ....#.
0000024: 01101110 00111110 00000100 10110010 10000010 00111111 n>...?
000002a: 10110101 01000001 11010000 10111110 01101011 01111111 .A..k.
0000030: 00011111 00111101 10111011 00101111 01010000 10111100 .=./P.
0000036: 11001101 11001100 01001100 00111101 00000000 00000000/@\tikzmark{endb}@/ ..L=..
000003c: /@\tikzmark{startc}@/00000000 00000000 01100111 00000000 10000000 00000001 ..g...
0000042: 00000001 01101000 10100000 11001110 00111111 01000010 .h..?B
0000048: 10011010 10101100 10111111 00000111 00010110 01100010 .....b
000004e: 01000000 01000010 00101010 01000011 10111101 11110111 @B*C..
0000054: 11101011 00000101 00111110 11001101 11001100 01001100/@\tikzmark{endc}@/ ..>..L
000005a: 00111101 00000000 00000000 00000000 00000000 01100111 =....g
0000060: 00000000 10000000 00000001 00000001 ....
$
\end{lstlisting}
\end{frame}
\end{document}
我们的想法是切换到listings
包,因为它可以逃逸到 LaTeX,然后使用该tikzmark
库在适当的位置放置一些标记;然后使用这些标记使用简单的\DrawBox
命令来绘制框架;该命令的两个参数是每个框的开始和结束标记。
该代码需要运行两到三次才能稳定下来。
答案2
这里我使用verbatimbox
包将逐字内容放在一个框中,以\scriptsize
适合页面大小。然后我使用 3 个嵌套的\stackinset
s 将红色矩形放在其上。
\documentclass[pdf]{beamer}
\usepackage{verbatimbox, stackengine}
\usepackage{xcolor}
\begin{document}
\begin{frame}[fragile]
\frametitle{IAEA phase-space file format}
\begin{verbbox}[\scriptsize]
$ xxd -b -l 100 ELEKTA_PRECISE_6mv_part1.IAEAphsp
0000000: 00000001 01101001 01010011 01001000 10111111 10100011 .iSH..
0000006: 11110110 10101101 11000000 01111110 00000100 10011110 ...~..
000000c: 11000000 11101011 10001011 10110101 10111110 01110011 .....s
0000012: 01110010 10100111 10111110 11001101 11001100 01001100 r....L
0000018: 00111101 00000100 00000000 00000000 00000000 01100111 =....g
000001e: 00000000 10000000 00000001 00000001 00100011 11011111 ....#.
0000024: 01101110 00111110 00000100 10110010 10000010 00111111 n>...?
000002a: 10110101 01000001 11010000 10111110 01101011 01111111 .A..k.
0000030: 00011111 00111101 10111011 00101111 01010000 10111100 .=./P.
0000036: 11001101 11001100 01001100 00111101 00000000 00000000 ..L=..
000003c: 00000000 00000000 01100111 00000000 10000000 00000001 ..g...
0000042: 00000001 01101000 10100000 11001110 00111111 01000010 .h..?B
0000048: 10011010 10101100 10111111 00000111 00010110 01100010 .....b
000004e: 01000000 01000010 00101010 01000011 10111101 11110111 @B*C..
0000054: 11101011 00000101 00111110 11001101 11001100 01001100 ..>..L
000005a: 00111101 00000000 00000000 00000000 00000000 01100111 =....g
0000060: 00000000 10000000 00000001 00000001 ....
$
\end{verbbox}
\stackinset{c}{2pt}{c}{58pt}{\textcolor{red}{\framebox(230,46){}}}{%
\stackinset{c}{2pt}{c}{10pt}{\textcolor{red}{\framebox(230,46){}}}{%
\stackinset{c}{2pt}{c}{-38pt}{\textcolor{red}{\framebox(230,46){}}}{%
\theverbbox}}}
\end{frame}
\end{document}