答案1
非常简短的近似:
\documentclass{article}
\usepackage{tikz}
\newcommand\xoutofeight[2][black]{%
\begin{tikzpicture}
\pgfmathsetlengthmacro\xstep{.6cm}
\pgfmathsetlengthmacro\ystep{\baselineskip}
\fill[#1!40] (0,0) rectangle ({#2*\xstep},\ystep);
\draw[#1,xstep=\xstep,ystep=\ystep] (0,0) grid ({8*\xstep},\ystep);
\end{tikzpicture}}
\begin{document}
short num: \xoutofeight{2}
char* str: \xoutofeight{8}
short num: \xoutofeight[green!80!black]{2}
\end{document}
答案2
简单的表格xcolor
可以array
做到这一点:
\documentclass{article}
\usepackage{array}
\usepackage[table, svgnames]{xcolor}
\begin{document}
\begin{center}
\setlength{\arrayrulewidth}{1.5pt}
\begin{tabular}{|*{8}{p{0.5cm}|}}
\hline
\rowcolor{WhiteSmoke!60!Lavender}& & & & & & &\rule{0pt}{1.5cm} \\
\hline
\end{tabular}\vskip 1cm
\begin{tabular}{|*{2}{>{\columncolor{WhiteSmoke!60!Lavender}}p{0.5cm}|}*{6}{p{0.5cm}|}}
\hline
& & & & & & &\rule{0pt}{1.5cm} \\
\hline
\end{tabular} \end{center}
\end{document}