16

I am writing some Chinese character and hope to draw simple pictures by tikz and use it as background of this chinese characters. In a short I'd like to get some results as this picture (ignore the lower right noise):

enter image description here

How could I do? Thanks in advance. As an example for least workable code:

\documentclass{article}
\usepackage[CJKnumber]{xeCJK}
\setmainfont{KaiTi}

\begin{document}
\Huge 明月出天山
\end{document}
  • How is the grid defined? What are its properties? – Qrrbrbirlbel Sep 16 '13 at 17:57
  • Note: CJKnumber option is invalid for latest versions of xeCJK. It is obsolete. Use zhnumber package if you need CJK numbers. – Leo Liu Sep 17 '13 at 6:01
17

The Basic grid behing the character is shown, also there is a new command added \Grid{}, to insert the needed glyph inside a specific grid:

\documentclass{article}
\usepackage{xeCJK}
\usepackage{tikz}
\setCJKmainfont{KaiTi}
%
\newcommand\Grid[1]{%
 \tikz[baseline=(char.base)]{%
  \draw[xstep=1ex,ystep=1ex,help lines] (-1ex,-1ex) grid (1ex,1ex);
  \node[inner sep=0pt] (char) at (0,0) {#1};
 }%
}
%
\begin{document}
%
\Huge 明月出天山
%
\Huge 明月出天\Grid{山}
%
\end{document}

The output is as follows:

enter image description here


Update

If a more nested grid is needed, one could apply a new parameter to the definition of \Grid{<step>}{<glyph>}, so modifing the command as:

\newcommand\Grid[2]{%
 \tikz[baseline=(char.base)]{%
  \draw[xstep=#1 ex,ystep=#1 ex,help lines] (-1ex,-1ex) grid (1ex,1ex);
  \node[inner sep=0pt] (char) at (0,0) {#2};
 }%
}

Gives for \Grid{1}{山} and \Grid{0.5}{山}:

enter image description here

| improve this answer | |
  • Since our answers are basically the same and you answered first, would you consider adding to your answer the definition of a command (as in my answer), so I can delete my answer? – Gonzalo Medina Sep 16 '13 at 17:37
  • @Gonzalo Medina Yes, sure. – TheVal Sep 16 '13 at 17:50
  • Answer deleted and +1 to your answer :-) – Gonzalo Medina Sep 16 '13 at 17:58
7

Using Andrea L. and Gonzalo Medina's solution we may get weird result of CJK puncuations. There are some problems in the previous solutions:

  • The position of grid should be relative to the base point of the character.
  • The width and height of the grid should be both 1em, not 2ex (characters are square in most CJK fonts).
  • The grids should be aligned.
  • The bounding box of the picture should be slightly smaller than the grid lines, since the line width is not ignorable.

PGFTricks's solution may be also problematic about puctuations.

Here is an improved version of Andrea's solution which carefully handles the depth of the glyphs and the bounding box.

\documentclass{article}

\usepackage{xeCJK}
\setCJKmainfont{KaiTi}

\usepackage{tikz}

% \grid for a single character
\newcommand\grid[1]{%
\begin{tikzpicture}[baseline=(char.base)]
  \path[use as bounding box]
    (0,0) rectangle (1em,1em);
  \draw[help lines,step=0.5em]
    (0,0) grid (1em,1em);
  \draw[help lines,dashed]
    (0,0) -- (1em,1em)  (0,1em) -- (1em,0);
  \node[inner sep=0pt,anchor=base west]
    (char) at (0em,\gridraiseamount) {#1};
\end{tikzpicture}}

% \gridraiseamount is a font-specific value
\newcommand\gridraiseamount{0.12em}

% \Grid for a CJK string
\makeatletter
\newcommand\Grid[1]{%
  \@tfor\z:=#1\do{\grid{\z}}}
\makeatother

\begin{document}

\Huge
\xeCJKsetup{PunctStyle=plain}

明月出天山,苍茫云海间。

\Grid{明月出天山,苍茫云海间。}

% We use a dash to test \gridraiseamount
\grid{—}

\end{document}

result picture

| improve this answer | |
  • I've also noticed that inside the definition of \grid the argument describing the step of the help lines could be implemented like: \grid[2]...\draw[help lines,step=#1 em], just to know. – TheVal Sep 17 '13 at 8:04
  • @AndreaL. Yes, that's possible. For Chinese characters, the grid is usually used to help children to learn to write. There're usually only two forms of girds, calld the “田” grid (田字格) and the “米” grid (米字格, the grid in my solution). – Leo Liu Sep 17 '13 at 8:52
  • Thanks for the delucidation, this is something new that I've learned on chinese typography now, because I've always thought that at school grids weren't needed; it's interesting. – TheVal Sep 17 '13 at 8:57
  • Thanks Andrea, PGFTricks and Leo! :) This helps a lot. I thinks the key points of this problem is [baseline=(char.base)] when define the picture. So glad to know this place and to know these warm heart friends. – Coeus Wang Sep 17 '13 at 11:57
5

With PSTricks.

Version 1

\documentclass[pstricks]{standalone}
\usepackage{CJKutf8}
\usepackage[overlap,CJK]{ruby}

\newpsstyle{gridstyle}{gridlabels=0pt,subgriddiv=1,gridcolor=lightgray}

\renewcommand\rubysep{-0.1ex}
\newsavebox\IBox

\newcommand\prepare[2][10]{\sbox\IBox{\raisebox{\depth}{\psscalebox{#1}{#2}}}}

\begin{document}
\begin{CJK*}{UTF8}{min}
\prepare{\ruby{忍}{にん}\ruby{者}{じゃ}}
\psset{xunit=\dimexpr\wd\IBox/2,yunit=\dimexpr\ht\IBox/2}
\begin{pspicture}[showgrid](2,2)
    \rput[bl](0,0){\usebox\IBox}
\end{pspicture}
\end{CJK*}
\end{document}

enter image description here

Version 2

\documentclass[pstricks]{standalone}
\usepackage{CJKutf8}
\usepackage[overlap,CJK]{ruby}

\newpsstyle{gridstyle}{gridlabels=0pt,subgriddiv=1,gridcolor=lightgray}

\renewcommand\rubysep{-0.1ex}
\newsavebox\IBox

\newcommand\prepare[2][10]{\sbox\IBox{\raisebox{\depth}{\psscalebox{#1}{#2}}}}

\begin{document}
\begin{CJK*}{UTF8}{min}
%\prepare{\ruby{忍}{にん}\ruby{者}{じゃ}}
\prepare[15]{犬}
\psset{xunit=\dimexpr\wd\IBox/2,yunit=\dimexpr\ht\IBox/2,linecolor=lightgray}
\begin{pspicture}[showgrid](2,2)
    \psline(2,0)(0,2)
    \psline(2,2)
    \rput[bl](0,0){\usebox\IBox}
\end{pspicture}
\end{CJK*}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.