具体表格布局

具体表格布局

我想绘制这样的表格: 桌子

表格宽度是线宽的一部分,例如 0.8 * 线宽。但我不知道该怎么做。

任何人?

编辑:MWE:

\documentclass[a4paper,12pt,headsepline]{report}
\geometry{left=2cm, right=2cm, top=2.5cm, bottom=2cm}
\linespread {1.25}\selectfont
\usepackage[nottoc]{tocbibind}
\frenchspacing
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{geometry}

\begin{document}

    %...
    % need table here
    % ...

\end{document}

答案1

\documentclass{report}
\usepackage{ragged2e,array}
\newcommand\MC[1]{\multicolumn{2}{|c}{%
  \tabular{@{\quad} >{\Centering}p{\dimexpr2.5cm} @{\quad}}
    CPU targets,\\byte offset #1\endtabular}}
\begin{document}

\begin{tabular}{*4{| p{1.25cm} | >{\RaggedLeft}p{1.25cm} }| }
31 & 24 & 23 & 16 & 15 & 8 & 7 & 0\\\hline
\MC3 & \MC2 & \MC1 & \MC0 \vrule\\\hline
\end{tabular}

\end{document}

在此处输入图片描述

答案2

bytefield您可以轻松获得帮助

\documentclass{article}
\usepackage{bytefield}

\begin{document}
\begin{bytefield}[bitheight=8ex,endianness=big]{32}
    \bitheader{31,24,23,16,15,8,7,0}\\
    \bitbox{8}{CPU targets,\\ byte offset 3}
    \bitbox{8}{CPU targets,\\ byte offset 2}
    \bitbox{8}{CPU targets,\\ byte offset 1}
    \bitbox{8}{CPU targets,\\ byte offset 0}
\end{bytefield}
\end{document}

在此处输入图片描述

答案3

以下是使用低级命令的实现:

\documentclass{article}

\makeatletter
\newcommand{\bitstable}[5][\columnwidth]{%
  $\m@th\vcenter{\vbox{\bits@table{#1}{#2}{#3}{#4}{#5}}}$%
}

\newcommand\bits@table[5]{%
  \offinterlineskip
  \@tempdima=#1\relax
  \advance\@tempdima-4\p@
  \@tempdima=.25\@tempdima
  \tabskip=\z@
  \halign{%
    \vrule##\hfil&
    ##&
    \hfil\vrule##\hfil&
    ##&
    \hfil\vrule##\hfil&
    ##&
    \hfil\vrule##\hfil&
    ##&
    \hfil\vrule##\cr
    &
    \footnotesize\rlap{\,31}\hfil\vrule\hfil\llap{24\,}&
    &
    \footnotesize\strut\rlap{\,23}\hfil\vrule\hfil\llap{16\,}&
    &
    \footnotesize\strut\rlap{\,15}\hfil\vrule\hfil\llap{8\,}&
    &
    \footnotesize\strut\rlap{\,7}\hfil\vrule\hfil\llap{0\,}&
    \cr
    height 1pt&\hfil\vrule\hfil&&\hfil\vrule\hfil&&\hfil\vrule\hfil&&\hfil\vrule\hfil&\cr
    \noalign{\hrule height 0.8pt}
    width0.8pt height 3pt&&
    width0.8pt&&
    width0.8pt&&
    width0.8pt&&
    width0.8pt\cr
    width0.8pt&
    \bits@tablebox{#2}&
    width0.8pt&
    \bits@tablebox{#3}&
    width0.8pt&
    \bits@tablebox{#4}&
    width0.8pt&
    \bits@tablebox{#5}&
    width0.8pt\cr
    width0.8pt height 3pt&&
    width0.8pt&&
    width0.8pt&&
    width0.8pt&&
    width0.8pt\cr
    \noalign{\hrule height 0.8pt}
  }%
}
\newcommand{\bits@tablebox}[1]{%
  \parbox{\@tempdima}{\centering\strut#1\strut}%
}
\makeatother

\begin{document}

\noindent
\bitstable
  {CPU targets\\ byte offset $3$}
  {CPU targets\\ byte offset $2$}
  {CPU targets\\ byte offset $1$}
  {CPU targets\\ byte offset $0$}

\bigskip

\noindent
\bitstable[.8\linewidth]
  {CPU targets\\ byte offset $3$}
  {CPU targets\\ byte offset $2$}
  {CPU targets\\ byte offset $1$}
  {CPU targets\\ byte offset $0$}

\end{document}

在此处输入图片描述

答案4

这里,我介绍\boxit如何制作每个单独的框。它需要 3 个参数(文本、高位和低位)。它还有一个框宽度的可选参数,默认为 0.2\textwidth,因此 4 个框占用 0.8\textwidth。

\documentclass{article}
\usepackage{lipsum}
\usepackage[usestackEOL]{stackengine}
\def\mystrut{\rule[-2pt]{\fboxrule}{2ex}}
\newcommand\boxit[4][.2\textwidth]{%
  \leavevmode\unskip%
  {\small\sffamily%
  \fboxsep=0pt%
  \def\stacktype{L}%
  \strutlongstacks{T}%
  \def\stackalignment{r}%
  \stackon{\def\stackalignment{l}%
  \stackon{\def\stackalignment{c}%
  \stackon{\fbox{\addstackgap[1pt]{\makebox[#1]{\Longunderstack{#2}}}}}{\mystrut}%
  }{\mystrut\,#3}%
  }{#4\,\mystrut}}%
  \kern-.5\fboxrule\ignorespaces%
}
\begin{document}
\lipsum[1]
\begin{center}
\boxit{CPU targets,\\byte offset 3}{31}{24}
\boxit{CPU targets,\\byte offset 2}{23}{16}
\boxit{CPU targets,\\byte offset 1}{15}{8}
\boxit{CPU targets,\\byte offset 0}{7}{0}
\end{center}
\lipsum[2]
\end{document}

在此处输入图片描述

相关内容