答案1
您可以使用基本的 LaTeX 来实现这一点,明确使用blkarray
和amsmath
:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{array, blkarray}
\begin{document}
\setlength{\BAextrarowheight}{2pt}
\makeatletter
\addtolength{\BA@colsep}{1pt}
\makeatother
\begin{blockarray}{*{7}{c}}
\begin{block}{|*{7}{c|}}
\BAhline
& &\makebox[0pt]{A} & \makebox[0pt]{B} & \makebox[0pt]{C}& & \\
\BAhline
\end{block}
& & \makebox[0pt]{$\stackrel{\uparrow}{\text{\scriptsize root\vphantom{l}}}$} & & \makebox[0pt]{$\stackrel{\uparrow}{\text{\scriptsize tail}}$}
\end{blockarray}
\begin{blockarray}{*{7}{c}}
\begin{block}{|*{7}{c|}}
\BAhline
& & & \makebox[0pt]{B} & \makebox[0pt]{C}& & \\
\BAhline
\end{block}
& & & \makebox[0pt]{$\stackrel{\uparrow}{\text{\scriptsize root\vphantom{l}\ }}$} & \makebox[0pt]{$\stackrel{\uparrow}{\text{\ \scriptsize tail}}$}
\end{blockarray}
\end{document}
答案2
欢迎!\if
您正在使用 Ti钾Z 很简单。
\documentclass{article}
\usepackage{tikz}
\newif\iffilled
\newcommand{\Diagram}[2][]{\begin{tikzpicture}[baseline=0em,#1]
\global\filledfalse
\foreach \X [count=\Y] in {#2}
{\draw (\Y*1.5em,0) rectangle ++ (1.5em,1.5em) node[midway]{\X};
\ifx\X\empty
\iffilled
\draw[latex-] (\Y*1.5em-0.75em,0) --++(0,-1em) node[below,font=\tiny] {tail};
\fi
\global\filledfalse
\else
\unless\iffilled
\draw[latex-] (\Y*1.5em+0.75em,0) --++(0,-1em) node[below,font=\tiny] {root};
\fi
\global\filledtrue
\fi}
\end{tikzpicture}}
\begin{document}
Bla bla
\[\Diagram{,,A,B,C,,}\]
bla bla
\[\Diagram{,,,B,C,,}\]
\end{document}