0

I want to create 10x10 squares and fill the elements all around with zeros

As shown in the attached images

enter image description here enter image description here enter image description here

But when I add zeros, a space appears between these elements.

Below is the MWE:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{matrix, backgrounds}

\newcommand{\0}{\scalebox{2}{$0$}}

\begin{document}

\begin{tikzpicture}[font=\scriptsize] \matrix (space) [matrix of math nodes, row sep=-\pgflinewidth, column sep=-\pgflinewidth, nodes={draw, semithick, minimum height=10mm, minimum width=10mm, text=blue}] {\0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 \};

\end{tikzpicture}

\begin{tikzpicture}[font=\scriptsize] \matrix (space) [matrix of math nodes, row sep=-\pgflinewidth, column sep=-\pgflinewidth, nodes={draw, semithick, minimum height=10mm, minimum width=10mm, text=blue}] {\ & \ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ &\ & \ & \ & \ & \ & \ & \ & \ & \ \ \ & \ & \ & \ & \ & \ & \ & \ & \ & \ \};

\end{tikzpicture}

\end{document}

Zarko
  • 296,517
Fadil
  • 21

2 Answers2

1

Try this code (you can change color and/or line width):

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
 \draw[gray!25,line width=.4pt] (0,0) grid (10,10);
 \foreach \x in {.5,1.5,...,9.5}{%
    \node at (\x,.5) () {\tiny 0};
    \node at (\x,9.5) () {\tiny 0};
    \node at (.5,\x) () {\tiny 0};
    \node at (9.5,\x) () {\tiny 0};
    };
\end{tikzpicture}
\end{document}

The output is:

enter image description here

EDIT: If you want black lines, more bigger '0' and want to write the '0' in the four corners one time only (whith some other little cosmetics) this code is better:

   \documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \draw[line width=.4pt] (0,0) grid (10,10);
        \foreach \x in {.5,1.5,...,9.5}{%
            \node[blue] at (\x,.5) () {\bfseries \small 0};
            \node[blue] at (\x,9.5) () {\bfseries \small 0};
        };
        \foreach \x in {1.5,...,8.5}{%
            \node[blue] at (.5,\x) () {\bfseries \small 0};
            \node[blue] at (9.5,\x) () {\bfseries \small 0};
        }
    \draw[red,line width=2pt] (0,0) rectangle (10,10);
    \draw[red,line width=2pt] (1,1) rectangle (9,9);
    \end{tikzpicture}
\end{document}

The new output is:

enter image description here

1

Other than anchor=center as Ignasi said in their comments, you can set text height and text depth:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{matrix, backgrounds}

\newcommand{\0}{\scalebox{2}{$0$}}

\begin{document}

\begin{tikzpicture}[font=\scriptsize] \matrix (space) [matrix of math nodes, row sep=-\pgflinewidth, column sep=-\pgflinewidth, nodes={draw, semithick, minimum height=10mm, minimum width=10mm, text height=7mm, text depth=3mm, inner sep=0pt, text=blue}] {\0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 &\ & \ & \ & \ & \ & \ & \ & \ & \0 \ \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 & \0 \}; \draw[red, very thick] (space-1-1.north west) rectangle (space-10-10.south east); \draw[red, very thick] (space-2-2.north west) rectangle (space-9-9.south east); \end{tikzpicture} \end{document}

enter image description here

CarLaTeX
  • 62,716