如何解决将数字添加到网格 Tikz LaTeX
如何在下面的网格之外添加数字。我尝试了以下代码,但它没有居中,我无法输入数字。
\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,\hauteur);
\draw[step=5cm,line width=0.5mm,black!10!black] (0,\hauteur);
\draw[step=1cm,line width=0.3mm,black!15!white] (0,\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,\hauteur);
\draw[step=5cm,line width=0.5mm,black!10!black] (0,\hauteur);
\draw[step=1cm,line width=0.3mm,black!15!white] (0,\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}
这将产生以下输出:
当然,如果您愿意,您仍然可以稍微调整间距。这会是您要寻找的结果吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。