下面你可以看到我的最小示例。看一下带有 \includegraphics 的第二个图。我可以添加一个引用字段,如下所示,并在图内添加一个表格。这个方法效果很好。我现在想做的是将相同的引用字段添加到字节字段,但它不起作用。我也尝试使用 \makebox,但这也导致没有解决方案。有人有什么想法吗?
\documentclass{article}
\usepackage{bytefield}
\usepackage{graphicx}
\newsavebox{\bytefieldbox}
\begin{document}
\pagestyle{empty}
\begin{figure}[]
\centering
\begin{bytefield}[bitwidth=1em]{32}
\bitheader{0-31} \\
\bitbox{4}{Version} & \bitbox{4}{IHL} & \bitbox{8}{Type of Service} & \bitbox{16}{Total Length} \\
\bitbox{16}{Identification} & \bitbox{3}{Flags} & \bitbox{13}{Fragment Offset} \\
\bitbox{8}{\emph{Time to Live}} & \bitbox{8}{Protocol} & \bitbox{16}{Header Checksum} \\
\bitbox{32}{\emph{Source Address}} \\
\bitbox{32}{\emph{Destination Address}}\\
\bitbox{24}{Options} & \bitbox{8}{Padding (if any)} \\
\end{bytefield}
\caption{some caption}
\end{figure}
\begin{figure}
\centering
\begin{tabular}{@{}r@{}}
\includegraphics[scale=0.5]{example-image-a}\\
{\footnotesize Source: based on ...}
\end{tabular}
\caption{some caption}
\end{figure}
\end{document}
谢谢
罗伯特
答案1
显然,bytefield
不喜欢在tabular
或在\sbox
。我建议一个低级技巧:
\documentclass{article}
\usepackage{bytefield}
\usepackage{graphicx}
\newsavebox{\bytefieldbox}
\newenvironment{sourcedbytefield}[3][]
{\def\source{#3}\setbox\bytefieldbox=\hbox\bgroup\begin{bytefield}[#1]{#2}}
{\end{bytefield}\egroup
\begin{tabular}{@{}r@{}}
\usebox{\bytefieldbox}\\
\footnotesize\source
\end{tabular}}
\newcommand{\sourcedincludegraphics}[3][]{%
\begin{tabular}{@{}r@{}}
\includegraphics[#1]{#2}\\
\footnotesize#3
\end{tabular}%
}
\begin{document}
\pagestyle{empty}
\begin{figure}[htp]
\centering
\begin{sourcedbytefield}[bitwidth=1em]{32}{Source: based on ...}
\bitheader{0-31} \\
\bitbox{4}{Version} & \bitbox{4}{IHL} & \bitbox{8}{Type of Service} & \bitbox{16}{Total Length} \\
\bitbox{16}{Identification} & \bitbox{3}{Flags} & \bitbox{13}{Fragment Offset} \\
\bitbox{8}{\emph{Time to Live}} & \bitbox{8}{Protocol} & \bitbox{16}{Header Checksum} \\
\bitbox{32}{\emph{Source Address}} \\
\bitbox{32}{\emph{Destination Address}}\\
\bitbox{24}{Options} & \bitbox{8}{Padding (if any)}
\end{sourcedbytefield}
\caption{some caption}
\end{figure}
\begin{figure}[htp]
\centering
\sourcedincludegraphics[scale=0.5]{example-image-a}{Source: based on ...}
\caption{some caption}
\end{figure}
\end{document}
\\
请注意,环境中不应该有尾随bytefield
(\\
从最后一行删除)。
答案2
如果你把它包装bytefield
成一个组{...}
,它就可以正常工作
\documentclass{article}
\usepackage{bytefield}
\usepackage{graphicx}
\newsavebox{\bytefieldbox}
\begin{document}
\pagestyle{empty}
\begin{figure}[]
\centering
\begin{tabular}{@{}r@{}}
{\lineskip=1pt
\begin{bytefield}[bitwidth=1em]{32}
\bitheader{0-31} \\
\bitbox{4}{Version} & \bitbox{4}{IHL} & \bitbox{8}{Type of Service} & \bitbox{16}{Total Length} \\
\bitbox{16}{Identification} & \bitbox{3}{Flags} & \bitbox{13}{Fragment Offset} \\
\bitbox{8}{\emph{Time to Live}} & \bitbox{8}{Protocol} & \bitbox{16}{Header Checksum} \\
\bitbox{32}{\emph{Source Address}} \\
\bitbox{32}{\emph{Destination Address}}\\
\bitbox{24}{Options} & \bitbox{8}{Padding (if any)}
\end{bytefield}
}\\
{\footnotesize Source: based on ...}
\end{tabular}
\caption{some caption}
\end{figure}
\begin{figure}
\centering
\begin{tabular}{@{}r@{}}
\includegraphics[scale=0.5]{example-image-a}\\
{\footnotesize Source: based on ...}
\end{tabular}
\caption{some caption}
\end{figure}
\end{document}