答案1
这是一个不使用 TikZ 的解决方案。
\documentclass{article}
\usepackage{array} % for 'w' column type
\usepackage{amsmath} % for '\smash[t]'
\newlength\mylen \settowidth\mylen{$-1$} % cell width in first 'array' env.
\begin{document}
\[
\setlength\extrarowheight{3pt}
\setlength\arraycolsep{2pt} % default: 5pt
G_x=\begin{array}{|*{2}{w{c}{\mylen}|}}
\hline -1 & 1 \\ \hline
\end{array}
\qquad
G_y=\smash[t]{
\begin{array}{|c|}
\multicolumn{1}{c}{} \\ \hline 1 \\ \hline -1 \\ \hline
\end{array}
}
\]
\end{document}
答案2
TikZ
以下是使用及其库的简短解决方案positioning
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\def\minboxsize{20pt}
\tikzset{boxnode/.style={draw,minimum height=\minboxsize,minimum width=\minboxsize}}
\node (A) {$G_x =$};
\node [boxnode,right of=A] (B) {$-1$};
\begin{scope}[node distance=\minboxsize]
\node [boxnode,right of=B] (C) {$1$};
\end{scope}
\node [right = 20pt of C](D) {$G_y =$};
\node [boxnode,right of=D] (E) {$1$};
\begin{scope}[node distance=\minboxsize]
\node [boxnode,below of=E] (F) {$-1$};
\end{scope}
\end{tikzpicture}
\end{document}