字节域不适用于子图

字节域不适用于子图

我正在尝试使用bytefieldsubfig(并且也测试了subfigure相同的结果)但是我收到了错误:

! 额外的对齐标签已更改

到 \cr.\endtemplate

在环境的末尾subfloat

下面的代码重现了这个问题

\documentclass{article}
\usepackage{bytefield}
\usepackage{subfig}

\begin{document}
\pagestyle{empty}
% this works
\begin{figure}
\begin{bytefield}{16}
\wordbox{1}{A 16-bit field} \\
\bitbox{8}{8 bits} & \bitbox{8}{8 more bits} \\
\wordbox{2}{A 32-bit field. Note that text wraps within the box.}
\end{bytefield}
\caption{Some caption}
\end{figure}

% this doesn't
\begin{figure}
\subfloat[]{
\begin{bytefield}{16}
\wordbox{1}{A 16-bit field} \\
\bitbox{8}{8 bits} & \bitbox{8}{8 more bits} \\
\wordbox{2}{A 32-bit field. Note that text wraps within the box.}
\end{bytefield}
}% the error is trown here
\subfloat[]{
\begin{bytefield}{16}
\wordbox{1}{A 16-bit field} \\
\bitbox{8}{8 bits} & \bitbox{8}{8 more bits} \\
\wordbox{2}{A 32-bit field. Note that text wraps within the box.}
\end{bytefield}
}% and here
\caption{Some caption}
\end{figure}

\end{document}

错误图片

答案1

在这种情况下,环境bytefield不喜欢成为命令的参数\subfloat

您可以使用保存箱和环境来补救lrbox

\documentclass{article}
\usepackage{bytefield}
\usepackage{subfig}
\newsavebox{\bytefieldbox}

\begin{document}
\pagestyle{empty}

\begin{figure}
\centering

\begin{lrbox}{\bytefieldbox}
\begin{bytefield}{16}
\wordbox{1}{A 16-bit field} \\
\bitbox{8}{8 bits} & \bitbox{8}{8 more bits} \\
\wordbox{2}{A 32-bit field. Note that text wraps within the box.}
\end{bytefield}
\end{lrbox}
\subfloat[]{\usebox{\bytefieldbox}}
%%%
\begin{lrbox}{\bytefieldbox}
\begin{bytefield}{16}
\wordbox{1}{A 16-bit field} \\
\bitbox{8}{8 bits} & \bitbox{8}{8 more bits} \\
\wordbox{2}{A 32-bit field. Note that text wraps within the box.}
\end{bytefield}
\end{lrbox}
\subfloat[]{\usebox{\bytefieldbox}}

\caption{Some caption}
\end{figure}

\end{document}

在此处输入图片描述

相关内容