![字节域不适用于子图](https://linux22.com/image/282027/%E5%AD%97%E8%8A%82%E5%9F%9F%E4%B8%8D%E9%80%82%E7%94%A8%E4%BA%8E%E5%AD%90%E5%9B%BE.png)
我正在尝试使用bytefield
和subfig
(并且也测试了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}