3

General overview

I make Chinese grids for handwriting exercice. The goal is to use the maximum space given in A4 page (with 1cm margin).

MWE

For the moment here is my code:

\documentclass[a4paper]{article}
\usepackage{xeCJK}
\usepackage{tikz}
\usepackage[margin=1cm]{geometry}
\pagenumbering{gobble}

\setCJKmainfont{AR PL UKai CN}

\newcommand\symbolbox[1]{%
\begin{tikzpicture}%
    \draw (0,0) rectangle (1,1);%
    \draw[gray] (0,0) -- (1,1);%
    \draw[gray] (0,1) -- (1,0);%
    \node at (0.5,0.5) {\Huge #1}; 
\end{tikzpicture}%%
%\hspace{-0.65em}
\hspace{-0.95em}
}%


\begin{document}

\raggedright
\noindent
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}
\symbolbox{你}


\end{document}

Current rendering

MWE rendering

MWE comments

As you see, I just multiply manually the call to the command \symbolbox ideally it should be looped.

The question

How to make the pattern be looped until it fills the page?

2
  • Will the pattern change?
    – MS-SPO
    Dec 5, 2023 at 13:24
  • No, it will always be \symbolbox{<someting>} (with a fixed someting all over the page.
    – fauve
    Dec 5, 2023 at 13:45

3 Answers 3

4

Here's a way to do it. Some remarks.

Tikz doesn't cooperate often with \newcommand. Use it's equivalent \pic inside of Tikz.

Here I called it symb. It outputs the same character. If you want to pass characters, look for \arg or args in the pgfmanual.

Both loops are set manually. Kindly watch the negative y-direction. Units are in cm. Call \pic like you would call \nodes, and pass the pic's name as text argument. See the pgfmanual to pass parameters to \pic.

You don't need/can't use vertical and horizontal spacings, unless you do it inside a nodes text field. Do all alignement by Tikz-means, which is setting coordinates, placement, anchors etc. most of the time.

For better visability I show frames. I couldn't set your default fonts.

% XeTex or XeLaTeX needed

\documentclass[a4paper]{article}
\usepackage{xeCJK}
\usepackage{tikz}
\usepackage[margin=1cm,showframe=true]{geometry}
\pagenumbering{gobble}

%\setCJKmainfont{AR PL UKai CN}


\begin{document}
 \begin{tikzpicture}[
    symb/.pic={
        \draw (0,0) rectangle (1,1);%
        \draw[gray] (0,0) -- (1,1);%
        \draw[gray] (0,1) -- (1,0);%
        \node at (0.5,0.5) {\Huge 你};
        },
 ]
    \foreach \x in {0,1,2,3,...,17}
        \foreach \y in {0,-1,-2,...,-26}
            \pic at (\x,\y) {symb};
 \end{tikzpicture}
\end{document}

result

1
  • Just a little improvement: is it posisble to get the 2 first lines in gray color with xcolor, the following 10 ones in lightgray and the remaining ones just void without any character?
    – fauve
    Dec 5, 2023 at 16:17
3

Don't insert \hspace in your definition:

\def\symbolbox #1{%
\begin{tikzpicture}%
    \draw (0,0) rectangle (1,1);%
    \draw[gray] (0,0) -- (1,1);%
    \draw[gray] (0,1) -- (1,0);%
    \node at (0.5,0.5) {\Huge #1}; 
\end{tikzpicture}%%
%\hspace{-0.65em}
%\hspace{-0.95em}
}%

and use \leaders TeX primitive

\begin{document}

\setbox0=\hbox{\symbolbox{你}}
\setbox0=\hbox to\hsize{\leaders\box0\hfil}

\topskip=0pt
\null \leaders\copy0\vfill
\break
\null \leaders\copy0\vfill
\break

\end{document}
3

W.r.t. your comment/question there are several ways to do it.

This approach uses the ifthen package. I applied it to modify Tikz code. You could also use xcolor inside the text field (inside the \pic), but you'd need to spend some effort on parameter passing.

Also if you want gray symbols but black grid, you need to spend some more effort to pass parameters to \pic.

I used the color mixer black!50, because I always forget it Tikz wants grey or gray here from the predefined colors ...

result

% XeTex or XeLaTeX needed

\documentclass[a4paper]{article}
\usepackage{xeCJK}
\usepackage{tikz}
\usepackage[margin=1cm,showframe=true]{geometry}
\pagenumbering{gobble}
\usepackage{ifthen}     % <<< new

%\setCJKmainfont{AR PL UKai CN}


\begin{document}
 \begin{tikzpicture}[
    symb/.pic={
        \draw (0,0) rectangle (1,1);%
        \draw[gray] (0,0) -- (1,1);%
        \draw[gray] (0,1) -- (1,0);%
        \node at (0.5,0.5) {\Huge 你};
        },
 ]
    \foreach \x in {0,1,2,3,...,17}
        \foreach \y in {0,-1,-2,...,-26}
            \ifthenelse{\y>-2}
                {\pic[black!50] at (\x,\y) {symb}}
                {\pic at (\x,\y) {symb}};
 \end{tikzpicture} 
\end{document}

You must log in to answer this question.

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