我想显示一个 L-Tromino。L-tromino 是由三个相等的正方形组成的形状,这些正方形的边缘连接在一起,形成一个类似于大写字母 L 的形状。我试过
\begin{array}{cc} \square& \\ \square&\square\end{array}
但这包含填充。如何对 2x2 表使用零填充?
答案1
\documentclass{article}
\usepackage{array,amssymb,tikz,graphicx}%
\begin{document}
Using \verb|tabular|:
\scalebox{.6}{%
\begin{tabular}{|c|c}\cline{1-1}
& \\\hline
& \multicolumn{1}{c|}{} \\\hline
\end{tabular}}
Compare the size with that of \verb|\square| : $\square$
Using \verb|TikZ| %% (just for fun as many of us are obsessed with tikz):
\begin{tikzpicture}[scale=.5]
\draw[thick] (0,0) -- (1,0) -- (1,.5) -- (0,.5) -- cycle;
\draw[thick] (0,.5) -- (0,1) -- (.5,1) -- (.5,0);
\end{tikzpicture}
\end{document}
\scalebox
PS:使用from减小了尺寸。在 tikz 中,使用graphicx
选项。scale
如果你经常使用它们,你可以定义一个宏,如下所示
\documentclass{article}
\usepackage{array,amssymb,tikz,graphicx}%
%
\newcommand{\Ltromino}{%
\scalebox{.6}{%
\begin{tabular}{|c|c}\cline{1-1}
& \\\hline
& \multicolumn{1}{c|}{} \\\hline
\end{tabular}}
}
%
\newcommand{\LTromino}{%
\begin{tikzpicture}[scale=.5]
\draw[thick] (0,0) -- (1,0) -- (1,.5) -- (0,.5) -- cycle;
\draw[thick] (0,.5) -- (0,1) -- (.5,1) -- (.5,0);
\end{tikzpicture}
}
\begin{document}
Using \verb|tabular|:
\Ltromino
Compare the size with that of \verb|\square| : $\square$
Using \verb|TikZ|:
\LTromino
\end{document}
答案2
\begin{array}{@{} c @{} c @{}}
\square & \\
\square & \square
\end{array}
答案3
当然,array
/的额外空格tabular
可以最小化为零:
\documentclass[12pt]{article}
\usepackage{amssymb}
\usepackage{color}
\setlength{\parskip}{1ex}
\begin{document}
$
\renewcommand*{\arraystretch}{0}
\begin{array}{@{}c@{}c@{}}
\square & \\
\square & \square
\end{array}
$
\begingroup
\renewcommand*{\arraystretch}{0}%
\setlength{\tabcolsep}{0pt}%
\setlength{\mathsurround}{0pt}%
\begin{tabular}{cc}
$\square$ &\\
$\square$ & $\square$
\end{tabular}%
\endgroup
\setlength{\fboxsep}{0pt}
\fbox{\textcolor{red}{$\square$}}
\end{document}
但这并不能解决你的问题:
字符框比字符本身大。黑色
\fbox
边框比红色边框宽\sqare
。这些空白称为左、右侧边距。这些值在 TeX 中是未知的。左下框的上线和上框的下线构成一条双倍线宽的水平线。此外,字形的线宽在 TeX 中是未知的。
因此我将通过图形进行绘制。以下示例tikz
还允许使用圆角:
\documentclass[12pt]{article}
\usepackage{amssymb}
\usepackage{tikz}
\newdimen\squareunit
\newdimen\squarelinewidth
\newcommand*{\BaseSquare}[1]{%
\begingroup
\settoheight{\squareunit}{$\square$}%
\setlength{\squarelinewidth}{.055\squareunit}%
\addtolength{\squareunit}{-\squarelinewidth}%
\begin{tikzpicture}[
x=\squareunit,
y=\squareunit,
line width=\squarelinewidth,
line join=round,
]
\draw[line join=round]#1;%
\end{tikzpicture}%
\endgroup
}
\newcommand*{\Square}{%
\BaseSquare{(0,0) rectangle (1,1)}%
}
\newcommand*{\Ltromino}{%
\BaseSquare{%
(0,0) -- (2,0) -- (2,1) -- (1,1) -- (1,2) -- (0,2) -- cycle
(0,1) -- (1,1) -- (1,0)
}%
}
\newcommand*{\ltromino}{%
\BaseSquare{%
(0,0) -- (1,0) -- (1,3) -- (0,3) -- cycle
(0,1) -- (1,1)
(0,2) -- (1,2)
}%
}
\begin{document}
$\square$\,\Square\,\Ltromino\,\ltromino
\end{document}