我只想创建一个像这,但没有数字或颜色,但我想代表一个n×n像这样用椭圆抽象地画网格:
另外,我需要的只是一个简单的单一网格,就像上图左上角的网格一样。
我知道需要一条从左下角到右上角的红线(y=x)。
答案1
一种非常基本的方法,使用grid
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (3,3);
\draw (0,4) grid (3,7);
\draw (4,0) grid (7,3);
\draw (4,4) grid (7,7);
\foreach \i/\valor in {1/1,2/2,3/3,5/n-2,6/n-1,7/n}
{
\node[anchor=south] at (\i-0.5,7) {$\valor$};
\node[anchor=east] at (0,-\i+7.5) {$\valor$};
}
\node at (3.5,1.5) {$\cdots$};
\node at (3.5,5.5) {$\cdots$};
\node at (1.5,3.5) {$\vdots$};
\node at (5.5,3.5) {$\vdots$};
\node at (3.5,3.5) {$\ddots$};
\end{tikzpicture}
\end{document}
随着编辑问题的新要求:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (3,3);
\draw (0,4) grid (3,7);
\draw (4,0) grid (7,3);
\draw (4,4) grid (7,7);
\foreach \i/\valor in {1/1,2/2,3/3,5/n-2,6/n-1,7/n}
{
\node[anchor=south] at (\i-0.5,7) {$\valor$};
\node[anchor=east] at (0,-\i+7.5) {$\valor$};
}
\node at (3.5,1.5) {$\cdots$};
\node at (3.5,5.5) {$\cdots$};
\node at (1.5,3.5) {$\vdots$};
\node at (5.5,3.5) {$\vdots$};
\node at (3.5,3.5) {$\ddots$};
\draw[red,ultra thick] (0,0) -- (7,7);
\end{tikzpicture}
\end{document}