将数字添加到网格Tikz LaTeX

将数字添加到网格Tikz LaTeX,latex,tikz,Latex,Tikz,如何在下方网格之外添加数字。我尝试了以下代码,但它没有居中,我无法输入数字 \documentclass{article} \usepackage{geometry} \geometry{hmargin=1cm,vmargin=1cm} \usepackage{tikz} \usetikzlibrary {shapes.geometric, arrows, arrows.meta} \def\width{20} \def\hauteur{25}

如何在下方网格之外添加数字。我尝试了以下代码,但它没有居中,我无法输入数字

  \documentclass{article}
    \usepackage{geometry}
    \geometry{hmargin=1cm,vmargin=1cm}
    \usepackage{tikz}
    \usetikzlibrary {shapes.geometric, arrows, arrows.meta}
    \def\width{20}
    \def\hauteur{25}
    \begin{document}
    \begin{tikzpicture}[x=1cm, y=1cm]
    \draw[step=1mm, line width=0.1mm, black!5!white] (0,0) grid (\width,\hauteur);
    \draw[step=5mm, line width=0.2mm, black!10!white] (0,0) grid (\width,\hauteur);
    \draw[step=5cm, line width=0.5mm, black!10!black] (0,0) grid (\width,\hauteur);
    \draw[step=1cm, line width=0.3mm, black!15!white] (0,0) grid (\width,\hauteur);
    \end{tikzpicture}
    \end{document}

您可以尝试结合使用
\foreach
循环和
\node
功能。我在下面添加了源代码:

\documentclass{article}
\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1cm}
\usepackage{tikz}
\usetikzlibrary {shapes.geometric, arrows, arrows.meta}
    
\def\width{20}
\def\hauteur{25}
    
\begin{document}
    \begin{tikzpicture}[x=1cm, y=1cm]
    \draw[step=1mm, line width=0.1mm, black!5!white] (0,0) grid (\width,\hauteur);
    \draw[step=5mm, line width=0.2mm, black!10!white] (0,0) grid (\width,\hauteur);
    \draw[step=5cm, line width=0.5mm, black!10!black] (0,0) grid (\width,\hauteur);
    \draw[step=1cm, line width=0.3mm, black!15!white] (0,0) grid (\width,\hauteur);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%% ADD THE PART BELOW %%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach \x in {0, ..., \width} {%
      % Bottom
      \node[anchor=north] at (\x,0) {\x};
      
      % Top
      \node[anchor=south] at (\x,\hauteur) {\x};
    }
    
    \foreach \y in {0, ..., \hauteur} {%
      % Left
      \node[anchor=east] at (0,\y) {\y};
      
      % Right
      \node[anchor=west] at (\width,\y) {\y};
    }
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \end{tikzpicture}
\end{document}
这将产生以下输出:


当然,如果您愿意,您仍然可以稍微调整间距。这就是您要寻找的结果吗?

您可以尝试结合使用
\foreach
循环和
\node
功能。我在下面添加了源代码:

\documentclass{article}
\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1cm}
\usepackage{tikz}
\usetikzlibrary {shapes.geometric, arrows, arrows.meta}
    
\def\width{20}
\def\hauteur{25}
    
\begin{document}
    \begin{tikzpicture}[x=1cm, y=1cm]
    \draw[step=1mm, line width=0.1mm, black!5!white] (0,0) grid (\width,\hauteur);
    \draw[step=5mm, line width=0.2mm, black!10!white] (0,0) grid (\width,\hauteur);
    \draw[step=5cm, line width=0.5mm, black!10!black] (0,0) grid (\width,\hauteur);
    \draw[step=1cm, line width=0.3mm, black!15!white] (0,0) grid (\width,\hauteur);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%% ADD THE PART BELOW %%%%%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \foreach \x in {0, ..., \width} {%
      % Bottom
      \node[anchor=north] at (\x,0) {\x};
      
      % Top
      \node[anchor=south] at (\x,\hauteur) {\x};
    }
    
    \foreach \y in {0, ..., \hauteur} {%
      % Left
      \node[anchor=east] at (0,\y) {\y};
      
      % Right
      \node[anchor=west] at (\width,\y) {\y};
    }
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    \end{tikzpicture}
\end{document}
这将产生以下输出:


当然,如果您愿意,您仍然可以稍微调整间距。这就是你想要的结果吗?

与其重新发明轮子,不如看一看pgfplotssamcarter,这不是我想要描绘的。我必须做一个完全不同的图表。请看下面。与其重新发明轮子,不如看一看pgfplotssamcarter,这不是我的意图。我必须做一个完全不同的图表。请看下面。