# How to simply draw matts for pupils writing Chinese character?

I want realize the effect like the following picture:

but I can only draw the picture like this:

Are there any simple methods drawing these matts?

 \documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{pinyin}
\begin{document}

\begin{tikzpicture}
\draw[dash pattern=on 2.2pt off 2.2pt](0,0)grid[step=0.5](1,1);
\draw[thick](0,0)rectangle(1,1);
\node at (0.5,1.3){\ping4};
\draw[dash pattern=on 2.2pt off 2.2pt](1.2,0)grid[step=0.5](2.2,1);
\draw[thick](1.2,0)rectangle(2.2,1);
\node at (1.7,1.3){\ba2};
\draw[dash pattern=on 2.2pt off 2.2pt](2.6,0)grid[step=0.5](3.6,1);
\draw[thick](2.6,0)rectangle(3.6,1);
\node at (3.1,1.3){\chuan2};
\draw[dash pattern=on 2.2pt off 2.2pt](3.8,0)grid[step=0.5](4.8,1);
\draw[thick](3.8,0)rectangle(4.8,1);
\node at (4.3,1.3){\dai4};
\end{tikzpicture}

\end{document}

• This seems like a good use of the \pic syntax in TikZ, to draw one grid and then repeat it as required. Alternatively you could draw one grid as a tikzpicture and reuse that. You method is heavily reliant on hand-positioned coordinates; a benefit of either of the methods I suggest would be freeing you up from that – Chris H Feb 14 '17 at 13:19
• @Chris But I need "pinyin" on the center of the grid top. How to realize that effect when I repeat using the same picture? – dozer Feb 14 '17 at 13:40

I suggest create one picture and repeat it in a table. To change the size change the scaling of \tikz.

\documentclass[11pt]{article}
\usepackage{geometry}\geometry{body={15cm,20cm}}
\usepackage{tikz}
\usepackage{pinyin}
\newcommand\matt[1]{%
\tikz[scale=0.5]{%
\draw[dashed,thin](0,0)grid(2,2);
\draw[thick](0,0)rectangle(2,2);
\node[anchor=south] at (1,2){\strut#1};
}}
\begin{document}
\begin{tabular}{ccccc}
\matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2}\\
\matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2}\\
\matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2}\\
\matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2} & \matt{\ping4} \matt{\ba2}
\end{tabular}
\end{document}


• Something's up with the text baselines, but overall I think this is the way to go – Chris H Feb 14 '17 at 13:56
• A very good method. However I find the pinyin don't align horizontally. Could you solve the problem? – dozer Feb 14 '17 at 13:56
• I've just noticed they don't align on my answer either, or on the question. – Chris H Feb 14 '17 at 13:59
• Changing [anchor=south] to [anchor=base] will fix the text alignment – Chris H Feb 14 '17 at 14:02
• I added a \strut to get alignment right. I think @ChrisH solution works as well. – StefanH Feb 14 '17 at 14:03

Just to show the quotes TikZ library for pics with text, and how to use the foreach statement.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{quotes}

\tikzset{
matt/.pic={
\draw (0,0) rectangle (1,1);
\draw[dashed] (0.5,0) -- (0.5,1);
\draw[dashed] (0,0.5) -- (1,0.5);
\draw (0.5,1) node[above] {\tikzpictext};
}
}

\begin{document}
% Inline use
\tikz\pic["p\ing"]{matt};
\tikz\pic["b\'a"]{matt};

\begin{tikzpicture}
\path (0,0)
\foreach \couple in {{p\ing, b\'a}, {chu\'an, d\ai}} {
\foreach \matt in \couple {
pic["\matt"]{matt} ++(1.2,0)
}
++(0.2,0)
};
\end{tikzpicture}
\end{document}


\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{pinyin}
\tikzset{
grid/.pic={
\draw[dash pattern=on 2.2pt off 2.2pt](0,0)grid[step=0.5](1,1);
\draw[thick](0,0)rectangle(1,1);
}
}

\begin{document}

\begin{tikzpicture}
\pic at (0,0) {grid};
\node at (0.5,1.3){\ping4};
\pic at (1.2,0) {grid};
\node at (1.7,1.3){\ba2};
\pic at (2.6,0) {grid};
\node at (3.1,1.3){\chuan2};
\pic at (3.8,0) {grid};
\node at (4.3,1.3){\dai4};
\end{tikzpicture}

\end{document}


• This is a simple manual illustration of using \pic. The other answers go further with automating it. – Chris H Feb 14 '17 at 13:55
• You helped me solve the problem that my grid can not step correctly, thank you very much. – dozer Feb 14 '17 at 13:59
• I'd been looking for a chance to use \pics anyway -- this was a nice question to try them out on. – Chris H Feb 14 '17 at 14:02
• @ChrisH You can add \node[above] at (0.5,1){\strut#1}; to your pic and call it with e.g. \pic at (0,0) {grid=\ping4}; – StefanH Feb 14 '17 at 14:09
• @StefanH, yes, but I saw your answer so just posted what I'd got – Chris H Feb 14 '17 at 14:48

Here are the boxes:

\documentclass{article}

\usepackage{tikz}
\newsavebox{\rectangle}

\newcommand{\boxme}[4]{%
\begin{tikzpicture}
\draw (0,0) rectangle (1,+1);
\draw[dashed] (0.5,0)--(0.5,1);
\draw[dashed] (0,0.5)--(1,0.5);
\end{tikzpicture}}

\begin{document}

\begin{tikzpicture}
\foreach \x in { 0,3,6,9,12}
\foreach \y in { 0,2,4,6,8}
{
\node at (\x,\y) {\boxme{}{}{}{}};
\node at (\x+1.1,\y) {\boxme{}{}{}{}};
}
\end{tikzpicture}
\end{document}

• a better method drawing the matts, thank you very much. – dozer Feb 14 '17 at 14:04