0

Background:

I have written up some code that creates a grid layout, so that it can be used to practice some Katakana/Hiragana characters.

Question:

How can I add a numbering system across the grids in the x and y direction with relatively small font size?

MWE:

\documentclass[a4paper]{article}
\pagestyle{empty}  % suppress page numbering
\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1cm}
\usepackage{tikz}
\def\mycolumns{18}
\def\myrows{25}


\begin{document}

\hspace{2cm}
\begin{center}
    \line(1,0){125}
\end{center}
\hspace{1cm}

\begin{tikzpicture}[x=1cm, y=1cm, semitransparent]
\draw[step=5mm, line width=0.2mm, black!40!white] (0,0) grid (\mycolumns,\myrows);
\draw[step=1cm, line width=0.3mm, black!90!white] (0,0) grid (\mycolumns,\myrows);
\end{tikzpicture}

\end{document}

Current Output:

enter image description here

Ideal Output:

The numbering should start from the top left as 1, and should align with the center-line of the boxes

enter image description here

Bonus Points:

If I can define the color of the numbers as "red" it would be awesome!

1 Answer 1

2

The following adds your numbers. To change the way they appear, you can alter the mynums style (e.g., to change the font size, you could add font=\small to the style).

\documentclass[a4paper]{article}
\pagestyle{empty}  % suppress page numbering
\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1cm}
\usepackage{tikz}
\def\mycolumns{18}
\def\myrows{25}


\begin{document}

\hspace{2cm}
\begin{center}
    \line(1,0){125}
\end{center}
\hspace{1cm}

\begin{tikzpicture}[x=1cm, y=1cm, semitransparent, mynums/.style={inner sep=0, text=red}]
\draw[step=5mm, line width=0.2mm, black!40!white] (0,0) grid (\mycolumns,\myrows);
\draw[step=1cm, line width=0.3mm, black!90!white] (0,0) grid (\mycolumns,\myrows);
\foreach\x in {1,...,\mycolumns}
  \node[anchor=south, mynums] at (\x-0.5, \myrows+0.25) {\x};
\foreach\x in {1,...,\myrows}
  \node[anchor=east, mynums] at (-0.25, \myrows - \x + 0.5) {\x};
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .