5

I'd like to visually divide a listing containing a hex dump into regions and provide a label for them.

Here's what I got so far:

hex dump with overlays

The code for this uses tcolorbox for the overlays and textpos to make them show up on top of the right area.

While I'm content with the outcome (although I'm open to different visualizations to mark the hex dump's regions), I'm looking for a way to make the overlays more robust. Currently, the overlays are positioned absolutely and thus require quite some trial and error to get right. This is fragile: If I add some text to the overlay labels or change the underlying hex dump, the overlays won't line up anymore.


Here's the code, I compiled it successfully with lualatex 1.12.0 on Arch Linux:

\documentclass{beamer}

\usepackage{listings}
\usepackage[most]{tcolorbox}
\usepackage[absolute,overlay]{textpos}

\definecolor{codebackground}{HTML}{EFF0F1}
\definecolor{codeforeground}{HTML}{34383C}

\newcommand{\code}[1]{
  \colorbox{codebackground}{\textcolor{codeforeground}{\texttt{{#1}}}}
}

% Hex dump background color
\definecolor{brightyellow}{HTML}{F7F5CD}

% Colors for overlays
\definecolor{fuchsia}{HTML}{8661C1}
\definecolor{pearl}{HTML}{E8E1D5}
\definecolor{darkgreen}{HTML}{204040}
\definecolor{lightolive}{HTML}{DADDC2}
\definecolor{lightlime}{HTML}{D6E6CC}
\definecolor{rose}{HTML}{F15BB5}
\definecolor{softpink}{HTML}{F7E0D3}

\begin{document}

\defverbatim[colored]\lstHexdumpFatNoFile{
  \begin{lstlisting}[ backgroundcolor=\color{brightyellow}, basicstyle=\tiny\ttfamily\color{codeforeground}, ]
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 04 04 00  |.<.mkfs.fat.....|
00000010  02 00 02 00 50 f8 14 00  20 00 02 00 00 00 00 00  |....P... .......|
00000020  00 00 00 00 80 00 29 10  61 b9 be 4d 59 20 44 52  |......).a..MY DR|
00000030  49 56 45 20 20 20 46 41  54 31 36 20 20 20 0e 1f  |IVE   FAT16   ..|
00000040  be 5b 7c ac 22 c0 74 0b  56 b4 0e bb 07 00 cd 10  |.[|.".t.V.......|
00000050  5e eb f0 32 e4 cd 16 cd  19 eb fe 54 68 69 73 20  |^..2.......This |
00000060  69 73 20 6e 6f 74 20 61  20 62 6f 6f 74 61 62 6c  |is not a bootabl|
00000070  65 20 64 69 73 6b 2e 20  20 50 6c 65 61 73 65 20  |e disk.  Please |
00000080  69 6e 73 65 72 74 20 61  20 62 6f 6f 74 61 62 6c  |insert a bootabl|
00000090  65 20 66 6c 6f 70 70 79  20 61 6e 64 0d 0a 70 72  |e floppy and..pr|
000000a0  65 73 73 20 61 6e 79 20  6b 65 79 20 74 6f 20 74  |ess any key to t|
000000b0  72 79 20 61 67 61 69 6e  20 2e 2e 2e 20 0d 0a 00  |ry again ... ...|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000800  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000810  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00003000  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00003010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00005800  4d 59 20 44 52 49 56 45  20 20 20 08 00 00 27 b1  |MY DRIVE   ...'.|
00005810  8e 52 8e 52 00 00 27 b1  8e 52 00 00 00 00 00 00  |.R.R..'..R......|
00005820  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00a00000
    \end{lstlisting}
}

\def\reservedSectorsRegionOverlay{
  \begin{textblock*}{10cm}(0.9cm, 1.8cm)
    \begin{tcolorbox}[enhanced jigsaw, opacityback=0.35, top=0mm,bottom=4.0mm, boxsep=14mm, colframe=fuchsia, colback=fuchsia!40] \begin{tcolorbox}[enhanced jigsaw, colback=pearl,opacityback=0.65, boxrule=0.0pt, left=0mm, right=0mm, boxsep=0mm, halign=center, leftright skip=1cm, colupper=codeforeground]Reserved Sectors Region\end{tcolorbox}\end{tcolorbox}
  \end{textblock*}
}

\def\firstFatOverlay{
  \begin{textblock*}{10cm}(0.9cm, 5.95cm)
    \begin{tcolorbox}[enhanced jigsaw, opacityback=0.35, top=0mm,bottom=0mm, boxsep=1mm, colframe=darkgreen, colback=darkgreen!40] \begin{tcolorbox}[enhanced jigsaw, colback=lightolive, opacityback=0.65, boxrule=0.0pt, left=0mm, right=0mm, top=0.5mm, bottom=0.5mm, boxsep=0mm, halign=center, leftright skip=3.2cm, colupper=codeforeground]\small{First FAT}\end{tcolorbox}\end{tcolorbox}
  \end{textblock*}
}

\def\secondFatOverlay{
  \begin{textblock*}{10cm}(0.9cm, 6.67cm)
    \begin{tcolorbox}[enhanced jigsaw, opacityback=0.35, top=0mm,bottom=0mm, boxsep=1mm, colframe=teal, colback=teal!40 ] \begin{tcolorbox}[enhanced jigsaw, colback=lightlime, opacityback=0.65, boxrule=0.0pt, left=0mm, right=0mm, top=0.5mm, bottom=0.5mm, boxsep=0mm, halign=center, leftright skip=3.2cm,colupper=codeforeground]\small{Second FAT}\end{tcolorbox}\end{tcolorbox}
  \end{textblock*}
}

\def\rootDirectoryOverlay{
  \begin{textblock*}{10cm}(0.9cm, 7.45cm)
    \begin{tcolorbox}[enhanced jigsaw, opacityback=0.35, top=1mm,bottom=0mm, boxsep=1mm, colframe=rose, colback=rose!40] \begin{tcolorbox}[enhanced jigsaw, colback=softpink, opacityback=0.65, boxrule=0.0pt, left=0mm, right=0mm, top=0.5mm, bottom=0.5mm, boxsep=0mm, halign=center, leftright skip=3.2cm, colupper=codeforeground]\small{Root Directory}\end{tcolorbox}\end{tcolorbox}
  \end{textblock*}
}

\frame{
  \frametitle{Brand New FAT16}
  \framesubtitle{Viewed with \code{hexdump -C}}

  \only<1-> \lstHexdumpFatNoFile
  \only<2-> \reservedSectorsRegionOverlay
  \only<3-> \firstFatOverlay
  \only<4-> \secondFatOverlay
  \only<5-> \rootDirectoryOverlay

}
\end{document}
9
  • Is there a positive reason why you're using textpos in absolute mode? The default relative mode sounds like a more natural fit to this case. Also, recall that textpos has \TPVertModule and \TPHorizModule to define the ‘units’ of vertical and horizontal spacing. If the former were the line-pitch of the underlying image, you might make things easier for yourself. Apr 17, 2021 at 10:07
  • One possibility would be to use the option of adding commands inside the listing and use tikzmark to mark spots. The problem is that you have to declare one ascii char to be the escape, and then you need to escape it manually when it occurs in the second column... Hmmm...
    – Rmano
    Apr 17, 2021 at 11:10
  • @NormanGray: Thanks a lot for creating textpos! I read the following in the documentation and didn't try relative mode: "The Beamer package’s background frame overlays the textpos material, unless the textpos & beamer [overlay] option is used to tell textpos to delay it. Therefore, you should use the [overlay,absolute] options with Beamer" Apr 17, 2021 at 21:16
  • @Rmano there's a tikzmark library that puts tikzmarks at loads of places in listing code. That might simplify that approach. Apr 18, 2021 at 19:50
  • @MatthiasBraun Ah, you're using beamer. On reflection, I'm not sure why that advice in the manual recommends using the absolute option with beamer (I've little experience with that, and may have been passing on some other user's advice). It might be that using absolute is good general advice for beamer, but not in fact necessary. Question: should I amend the manual's advice here? Apr 18, 2021 at 22:11

2 Answers 2

4

Update: using tikzmarklisings library

This is just an update of my previous answer which solves two problems.

The first one was caused because tcolorbox overlays are placed before the text. This means that label for each code part was behind listing. This has been solved placing colored rectangles into an overlay option, but labels into a finish option which is always drawn above the text.

The second problem was the use of manual references. This has been solved using tikzmarklistings library in a similar way as shown in Andrew Stacey's answer.

The third change has been to simplify the code using a \newtcblisting environment.

The code is:

\documentclass{beamer}

\usepackage{listings}
\usepackage[most, hooks]{tcolorbox}
%\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzmarklibrary{listings}

\definecolor{codebackground}{HTML}{EFF0F1}
\definecolor{codeforeground}{HTML}{34383C}

\newcommand{\code}[1]{
  \colorbox{codebackground}{\textcolor{codeforeground}{\texttt{{#1}}}}
}

% Hex dump background color
\definecolor{brightyellow}{HTML}{F7F5CD}

% Colors for overlays
\definecolor{fuchsia}{HTML}{8661C1}
\definecolor{pearl}{HTML}{E8E1D5}
\definecolor{darkgreen}{HTML}{204040}
\definecolor{lightolive}{HTML}{DADDC2}
\definecolor{lightlime}{HTML}{D6E6CC}
\definecolor{rose}{HTML}{F15BB5}
\definecolor{softpink}{HTML}{F7E0D3}

\tikzset{
    labelnode/.style={midway, sharp corners, 
        text opacity=1, fill opacity=.65, fill=#1, font=\small},
    frame/.style={ultra thick, rounded corners, 
        draw=#1, fill=#1!40, fill opacity=.35},
}

\newtcblisting{hexdump}[1][]{%
    enhanced, listing only,
    remember as=mylisting,
    sharp corners, sharp corners, notitle,
    size=minimal, boxrule=0pt,
    colback=brightyellow, colupper=black,
    listing options={%
        name=code, basicstyle=\tiny\ttfamily, firstnumber=1},
    #1,
}

\begin{document}

\begin{frame}[fragile]
  \frametitle{Brand New FAT16}
  \framesubtitle{Viewed with \code{hexdump -C}}

\begin{hexdump}[%
    only=<2->{%
        overlay app={\draw[frame=fuchsia] (pic cs:line-code-0-start) 
                rectangle (pic cs:line-code-16-end);}, 
        finish={\path (pic cs:line-code-0-start) -- node[labelnode=pearl] {Reserved Sectors Region} (pic cs:line-code-16-end);}
    },
    only=<3->{%
        overlay app={\draw[frame=darkgreen] (pic cs:line-code-17-start) 
                rectangle (pic cs:line-code-19-end);},
        finish={\path (pic cs:line-code-17-start) -- node[labelnode=lightolive]{First FAT}  (pic cs:line-code-19-end);}
    },
    only=<4->{%
        overlay app={\draw[frame=teal] (pic cs:line-code-20-start) 
                rectangle (pic cs:line-code-22-end);},
        finish={\path (pic cs:line-code-20-start) -- node[labelnode=lightlime]{Second FAT}  (pic cs:line-code-22-end);}
    },
    only=<5->{%
        overlay app={\draw[frame=rose] (pic cs:line-code-23-start) 
                rectangle (pic cs:line-code-26-end);},
        finish={\path (pic cs:line-code-23-start) -- node[labelnode=softpink]{Root Directory}  (pic cs:line-code-26-end);}
    }
]
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 04 04 00  |.<.mkfs.fat.....|
00000010  02 00 02 00 50 f8 14 00  20 00 02 00 00 00 00 00  |....P... .......|
00000020  00 00 00 00 80 00 29 10  61 b9 be 4d 59 20 44 52  |......).a..MY DR|
00000030  49 56 45 20 20 20 46 41  54 31 36 20 20 20 0e 1f  |IVE   FAT16   ..|
00000040  be 5b 7c ac 22 c0 74 0b  56 b4 0e bb 07 00 cd 10  |.[|.".t.V.......|
00000050  5e eb f0 32 e4 cd 16 cd  19 eb fe 54 68 69 73 20  |^..2.......This |
00000060  69 73 20 6e 6f 74 20 61  20 62 6f 6f 74 61 62 6c  |is not a bootabl|
00000070  65 20 64 69 73 6b 2e 20  20 50 6c 65 61 73 65 20  |e disk.  Please |
00000080  69 6e 73 65 72 74 20 61  20 62 6f 6f 74 61 62 6c  |insert a bootabl|
00000090  65 20 66 6c 6f 70 70 79  20 61 6e 64 0d 0a 70 72  |e floppy and..pr|
000000a0  65 73 73 20 61 6e 79 20  6b 65 79 20 74 6f 20 74  |ess any key to t|
000000b0  72 79 20 61 67 61 69 6e  20 2e 2e 2e 20 0d 0a 00  |ry again ... ...|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000800  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000810  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00003000  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00003010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00005800  4d 59 20 44 52 49 56 45  20 20 20 08 00 00 27 b1  |MY DRIVE   ...'.|
00005810  8e 52 8e 52 00 00 27 b1  8e 52 00 00 00 00 00 00  |.R.R..'..R......|
00005820  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00a00000
\end{hexdump}
\end{frame}
\end{document}

enter image description here

Original answer:

I don't know how to place tikzmarks inside a listing, but this alternative construction for OP's listing, can avoid using textpos package.

This proposal suggests to use a tcblisting (instead of a lstlisting). As a tcblisting is inside a tcolorbox, its frame anchors can be used as a reference for the overlayed regions. These regions can be drawn by an overlay app option inside the listing, and it's also possible to use only tcolorbox option to specify in which frame to apply each one.

In this case we have to use overlay app (from hooks library) because overlays are not stackables, the new ones replaces the previous ones. With overlay app it's possible to add all of them.

All regions dimensions have been defined with trial and error method, but at least, they make reference to the underlayed listing and not to the general frame.

\documentclass{beamer}

\usepackage{listings}
\usepackage[most, hooks]{tcolorbox}

\definecolor{codebackground}{HTML}{EFF0F1}
\definecolor{codeforeground}{HTML}{34383C}

\newcommand{\code}[1]{
  \colorbox{codebackground}{\textcolor{codeforeground}{\texttt{{#1}}}}
}

% Hex dump background color
\definecolor{brightyellow}{HTML}{F7F5CD}

% Colors for overlays
\definecolor{fuchsia}{HTML}{8661C1}
\definecolor{pearl}{HTML}{E8E1D5}
\definecolor{darkgreen}{HTML}{204040}
\definecolor{lightolive}{HTML}{DADDC2}
\definecolor{lightlime}{HTML}{D6E6CC}
\definecolor{rose}{HTML}{F15BB5}
\definecolor{softpink}{HTML}{F7E0D3}

\tikzset{
    labelnode/.style={midway, sharp corners, text opacity=1, fill opacity=1, fill=#1!85!black, font=\small},
    frame/.style={ultra thick, rounded corners, draw=#1, fill=#1!40, fill opacity=.35},
}

\begin{document}

\begin{frame}[fragile]
  \frametitle{Brand New FAT16}
  \framesubtitle{Viewed with \code{hexdump -C}}

\begin{tcblisting}{%
    enhanced, listing only, notitle, sharp corners, size=tight, boxrule=0pt, colback=brightyellow, 
    listing options={basicstyle=\tiny\ttfamily}, colupper=codeforeground, top=0pt,
    only=<2->{%
        overlay app={\draw[frame=fuchsia] (frame.north west) 
                rectangle ++(9.85,-4.15) node[labelnode=pearl]{Reserved Sectors Region};}
    },
    only=<3->{%
        overlay app={\draw[frame=darkgreen] ([yshift=-4.3cm]frame.north west) 
                rectangle ++(9.85,-.6) node[labelnode=lightolive]{First FAT};}
    },
    only=<4->{%
        overlay app={\draw[frame=teal] ([yshift=-5.05cm]frame.north west) 
                rectangle ++(9.85,-.6) node[labelnode=lightlime]{Second FAT};}
    },
    only=<5->{%
        overlay app={\draw[frame=rose] ([yshift=-5.8cm]frame.north west) 
                rectangle ++(9.85,-.75) node[labelnode=softpink]{Root Directory};}
    },
}
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 04 04 00  |.<.mkfs.fat.....|
00000010  02 00 02 00 50 f8 14 00  20 00 02 00 00 00 00 00  |....P... .......|
00000020  00 00 00 00 80 00 29 10  61 b9 be 4d 59 20 44 52  |......).a..MY DR|
00000030  49 56 45 20 20 20 46 41  54 31 36 20 20 20 0e 1f  |IVE   FAT16   ..|
00000040  be 5b 7c ac 22 c0 74 0b  56 b4 0e bb 07 00 cd 10  |.[|.".t.V.......|
00000050  5e eb f0 32 e4 cd 16 cd  19 eb fe 54 68 69 73 20  |^..2.......This |
00000060  69 73 20 6e 6f 74 20 61  20 62 6f 6f 74 61 62 6c  |is not a bootabl|
00000070  65 20 64 69 73 6b 2e 20  20 50 6c 65 61 73 65 20  |e disk.  Please |
00000080  69 6e 73 65 72 74 20 61  20 62 6f 6f 74 61 62 6c  |insert a bootabl|
00000090  65 20 66 6c 6f 70 70 79  20 61 6e 64 0d 0a 70 72  |e floppy and..pr|
000000a0  65 73 73 20 61 6e 79 20  6b 65 79 20 74 6f 20 74  |ess any key to t|
000000b0  72 79 20 61 67 61 69 6e  20 2e 2e 2e 20 0d 0a 00  |ry again ... ...|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000800  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000810  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00003000  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00003010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00005800  4d 59 20 44 52 49 56 45  20 20 20 08 00 00 27 b1  |MY DRIVE   ...'.|
00005810  8e 52 8e 52 00 00 27 b1  8e 52 00 00 00 00 00 00  |.R.R..'..R......|
00005820  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00a00000
\end{tcblisting}
\end{frame}
\end{document}

enter image description here

9
  • "I don't know how to place tikzmarks inside a listing" -- I do! \usetikzmarklibrary{listings} puts tikzmarks just about everywhere in a listing environment. See the documentation for details. Apr 18, 2021 at 19:44
  • Wow @Ignasi, thanks for your answer, this looks great. I'm not sure whether this is only on my end, but the labels are below the hex dump, which makes them more difficult to read: i.imgur.com/Q9UDlt1.png Apr 19, 2021 at 8:31
  • 1
    @MatthiasBraun Yes, you're right. tcolorbox overlays are drawn before the text. But if you replace all overlay app by finish they will be drawn after text.
    – Ignasi
    Apr 19, 2021 at 11:03
  • 1
    @Ignasi That's great! I love it when answers build on each other. Apr 20, 2021 at 16:30
  • 1
    @MatthiasBraun yes you can do it, but you confused the parameters. You should say, \newtcblisting[2][]{..., listing options={name=#2, ...}, #1 and when you call it, the name of the code is a mandatory parameter after the optional: \begin{hexdump}[overlay...]{code's name}. But you also have to use code's name into pic cs references into the optional parameter.
    – Ignasi
    Apr 26, 2021 at 10:23
3

The tikzmark TikZ library has a library of its own that puts tikzmarks at various points in a listings code environment. Using this, we can define boxes that cover certain regions of the code reasonably naturally. It uses the line numbers, which means that the issue with beamer and line numbers comes in to play, but there is a workaround for that using the firstnumber key.

\documentclass{beamer}
%\url{https://tex.stackexchange.com/q/593230/86}

\usepackage{tikz}
\usepackage{listings}
\usetikzlibrary{tikzmark,calc}
\usetikzmarklibrary{listings}

\resetcounteronoverlays{lstnumber}

\definecolor{codebackground}{HTML}{EFF0F1}
\definecolor{codeforeground}{HTML}{34383C}

\newcommand{\code}[1]{
  \colorbox{codebackground}{\textcolor{codeforeground}{\texttt{{#1}}}}
}

% Hex dump background color
\definecolor{brightyellow}{HTML}{F7F5CD}

% Colors for overlays
\definecolor{fuchsia}{HTML}{8661C1}
\definecolor{pearl}{HTML}{E8E1D5}
\definecolor{darkgreen}{HTML}{204040}
\definecolor{lightolive}{HTML}{DADDC2}
\definecolor{lightlime}{HTML}{D6E6CC}
\definecolor{rose}{HTML}{F15BB5}
\definecolor{softpink}{HTML}{F7E0D3}

\begin{document}

\begin{frame}[fragile]
  \frametitle{Brand New FAT16}
  \framesubtitle{Viewed with \code{hexdump -C}}

\begin{tikzpicture}[
  remember picture,
  overlay,
  box/.style={
    draw=#1,
    fill=#1!40,
    rounded corners,
    line width=2pt
  }
]
\path<2->[
  box=fuchsia
]
([shift={(-.25,.125)}]pic cs:line-hexdump-0-start)
rectangle
([shift={(.25,-.125)}]pic cs:line-hexdump-16-end);
\path<3->[
  box=darkgreen
]
([shift={(-.25,.125)}]pic cs:line-hexdump-17-start)
rectangle
([shift={(.25,-.125)}]pic cs:line-hexdump-19-end);
\path<4->[
  box=teal
]
([shift={(-.25,.125)}]pic cs:line-hexdump-20-start)
rectangle
([shift={(.25,-.125)}]pic cs:line-hexdump-22-end);
\path<5->[
  box=rose
]
([shift={(-.25,.125)}]pic cs:line-hexdump-23-start)
rectangle
([shift={(.25,-.125)}]pic cs:line-hexdump-26-end);
\end{tikzpicture}

\begin{lstlisting}[
  basicstyle=\tiny\ttfamily,
  name=hexdump,
%  numbers=left,
  firstnumber=1
]
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 04 04 00  |.<.mkfs.fat.....|
00000010  02 00 02 00 50 f8 14 00  20 00 02 00 00 00 00 00  |....P... .......|
00000020  00 00 00 00 80 00 29 10  61 b9 be 4d 59 20 44 52  |......).a..MY DR|
00000030  49 56 45 20 20 20 46 41  54 31 36 20 20 20 0e 1f  |IVE   FAT16   ..|
00000040  be 5b 7c ac 22 c0 74 0b  56 b4 0e bb 07 00 cd 10  |.[|.".t.V.......|
00000050  5e eb f0 32 e4 cd 16 cd  19 eb fe 54 68 69 73 20  |^..2.......This |
00000060  69 73 20 6e 6f 74 20 61  20 62 6f 6f 74 61 62 6c  |is not a bootabl|
00000070  65 20 64 69 73 6b 2e 20  20 50 6c 65 61 73 65 20  |e disk.  Please |
00000080  69 6e 73 65 72 74 20 61  20 62 6f 6f 74 61 62 6c  |insert a bootabl|
00000090  65 20 66 6c 6f 70 70 79  20 61 6e 64 0d 0a 70 72  |e floppy and..pr|
000000a0  65 73 73 20 61 6e 79 20  6b 65 79 20 74 6f 20 74  |ess any key to t|
000000b0  72 79 20 61 67 61 69 6e  20 2e 2e 2e 20 0d 0a 00  |ry again ... ...|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000800  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000810  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00003000  f8 ff ff ff 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00003010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00005800  4d 59 20 44 52 49 56 45  20 20 20 08 00 00 27 b1  |MY DRIVE   ...'.|
00005810  8e 52 8e 52 00 00 27 b1  8e 52 00 00 00 00 00 00  |.R.R..'..R......|
00005820  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00a00000
\end{lstlisting}

\begin{tikzpicture}[
  remember picture,
  overlay,
  label node/.style={
    sharp corners,
    fill=#1!85!black,
    font=\small
  },
]
\node<2>[
  label node=pearl
] at
($(pic cs:line-hexdump-0-start)!.5!(pic cs:line-hexdump-16-end)$)
{Reserved Sectors Region};
\node<3>[
  label node=lightolive
] at
($(pic cs:line-hexdump-17-start)!.5!(pic cs:line-hexdump-19-end)$)
{First FAT};
\node<4>[
  label node=lightlime
] at
($(pic cs:line-hexdump-20-start)!.5!(pic cs:line-hexdump-22-end)$)
{Second FAT};
\node<5>[
  label node=softpink
] at
($(pic cs:line-hexdump-23-start)!.5!(pic cs:line-hexdump-26-end)$)
{Root Directory};
\end{tikzpicture}

\end{frame}
\end{document}

To figure out the right marks to use, you can uncomment the line numbers=left to show the line numbers. The marks are placed at the baseline of the line, so using the mark on the previous line for the top of the box looks better.

I've used a tikzpicture before the code to place the boxes which means that they are underneath the code and don't obscure it. I've used a second tikzpicture after the code to place the labels so that they are placed on top and are therefore readable.

listings with tikzmarks in beamer

References:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .