0 1 2 3
R R R R
*¯¯¯*¯¯¯*¯¯¯*
* a | b | c |
*___*___*___*
L L L L
我想创建一个类似于上面的网格,它将是一个每个单元格只有一个字母的网格,并且在每个单元格分隔线上,顶部有 R,底部有 L,此外,在每个单元格分隔线上还有从 0 开始的数字;如上所示。
* 和 ¯¯ 字符只是为了说明目的,我更喜欢实际的网格图案。
答案1
如果没有关于格式化的更多信息,以下是比蛮力方法稍微不那么重要的东西:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\matrix [column sep=0pt,every node/.style={draw,inner sep=1.5ex,text depth=0.5ex,text height=1.5ex,anchor=base}]
{
\node(m0) {a}; & \node(m1) {b}; & \node(m2) {c}; \\
};
\foreach \myletter [count=\x from=0] in {0,1,2,3}
{
\ifnum\x<3\relax
\node[anchor=south] (R\x) at (m\x.north west) {R};
\node[anchor=north] (L\x) at (m\x.south west) {L};
\else
\node[anchor=south] (R\x) at (m2.north east) {R};
\node[anchor=north] (L\x) at (m2.south east) {L};
\fi
\node[anchor=south] at (R\x.north) {\x};
}
\end{tikzpicture}
\end{document}
答案2
这是使用该包的简单解决方案blkarray
:我利用这样一个事实:在blockarray
环境中,不同的块可以有不同的列分隔符:
\documentclass{article}
\usepackage{blkarray}
\usepackage{geometry}
\newcounter{col}
\usepackage{xcolor}
\usepackage{stackengine}
\setstackEOL{\\}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}
\usepackage{dashrule}
\newcommand\dashfill{\leavevmode\cleaders\hbox{\rule{2.5pt}{0.3pt}\hskip2pt}\hfill\kern0pt}
\newcommand\vardashfill{\leavevmode\cleaders\hbox{\rule[0.25ex]{2.5pt}{0.3pt}\hskip2pt}\hfill\kern0pt}
\begin{document}
\centering
\setcounter{col}{0}
\begin{blockarray}{*{3}{c}}
\begin{block}{@{\makebox[0pt]{\thecol}\stepcounter{col}}*{3}{c@{\makebox[0pt]{\thecol}\stepcounter{col}}}}
& & \\
\end{block}
\begin{block}{@{\makebox[0pt]{R}}*{3}{c@{\makebox[0pt]{R}}}}
& & \\[-1.5ex]
\end{block}
\begin{block}{@{\makebox[0pt]{\tiny\textbullet}}*{3}{>{\vardashfill}c@{\makebox[0pt]{\tiny\textbullet}}}}
& & \\[-0.5ex]
\end{block}
\begin{block}{@{\hskip\tabcolsep}*{3}{>{\Large}c|}}
a & b & c \\[-1.2ex]
\end{block}
\begin{block}{@{\makebox[0pt]{\tiny\textbullet}}*{3}{ >{\vardashfill}c@{\makebox[0pt]{\tiny\textbullet}}}}
& & \\[-0.5ex]
\end{block}
\begin{block}{@{\makebox[0pt]{L}}*{3}{c@{\makebox[0pt]{L}}}}
& & \\
\end{block}
\end{blockarray}
\end{document}