答案1
用 LaTeX 中的一些框和移动就可以实现。从代码角度来看,图形方法可能更容易阅读。
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\[
\newcommand{\largestrut}{\rule[-.8\baselineskip]{0pt}{2\baselineskip}}%
\newcommand{\smallstrut}{\rule[-.5\baselineskip]{0pt}{1.4\baselineskip}}%
\rlap{%
\fcolorbox{black}{black!15}{%
\largestrut$x_1 \quad x_2 \quad \phantom{x_3}$%
}%
\hspace{\dimexpr-\fboxrule-\fboxsep}%
$\quad \phantom{x_4} \quad$%
\hspace{\dimexpr-\fboxrule-\fboxsep}%
\fcolorbox{black}{black!15}{%
\largestrut$\phantom{x_5} \quad x_6 \quad \phantom{x_7}$%
}%
}%
\setlength{\fboxrule}{1.5\fboxrule}%
\hspace{\dimexpr0.6666\fboxrule+\fboxsep+1em-\fboxrule-\fboxsep}%
\phantom{x_1 \quad x_2}
\fcolorbox{black}{black!30}{%
\smallstrut $x_3 \quad x_4 \quad x_5$%
}%
\hspace{\dimexpr-\fboxrule-\fboxsep}%
\phantom{\quad x_6 \quad}%
\hspace{\dimexpr-\fboxrule-\fboxsep}%
\fcolorbox{black}{black!30}{%
\smallstrut $x_7 \quad \cdots$%
}%
\]
% For reference (without the boxes)
\[
x_1 \quad x_2 \quad x_3 \quad x_4 \quad x_5 \quad x_6 \quad x_7 \quad \cdots
\]
\end{document}
答案2
利用nicematrix
包定义的 PGF/Tikz 节点,代码更简单且更易于维护。
它由一个表格和一些线条和彩色矩形组成。
首次會拍摄兩部合辑。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{xcolor, colortbl}
\usepackage{nicematrix}
\begin{document}
\renewcommand{\arraystretch}{0.5}
$\begin{NiceArray}{c cccc cccc c}[
code-before =\rectanglecolor{black!15}{1-1}{5-4},
code-before =\rectanglecolor{black!15}{1-6}{5-8},
code-before =\rectanglecolor{gray!85}{2-4}{4-6},
code-before =\rectanglecolor{gray!85}{2-8}{4-9},
]
&&&&&&&&&\\
&&&&&&&&&\\
& x_1 & x_2 & x_3 & x_4 & x_5 & x_6 & x_7 & \cdots\quad &\\
&&&&&&&&&\\
&&&&&&&&&\\
\CodeAfter
\tikz{%
\draw[line width=0.7pt] (row-1-|col-1) -- (row-6-|col-1)-- (row-6-|col-5) --(row-5-|col-5);
\draw[line width=0.7pt] (row-1-|col-1) -- (row-1-|col-5)-- (row-2-|col-5);
\draw[line width=1.0pt](row-2-|col-4) -- (row-5-|col-4)-- (row-5-|col-7) -- (row-2-|col-7) --cycle;
\draw[line width=1.0pt](row-2-|col-10) -- (row-2-|col-8)-- (row-5-|col-8) -- (row-5-|col-10);
\draw[line width=0.7pt](row-2-|col-9) -- (row-1-|col-9)-- (row-1-|col-6) -- (row-2-|col-6);
\draw[line width=0.7pt](row-5-|col-9) -- (row-6-|col-9)-- (row-6-|col-6) -- (row-5-|col-6);
}
\end{NiceArray}$
\end{document