16

I wanted to create a simple sort of template, for printing and then using by hand.

The one I want to create is called Genkō yōshi (原稿用紙, "manuscript paper"), which is nothing more than those squares in vertical position for both writing and practicing Japanese.

This is what I want to do (A4 page):

enter image description here

Note: they must be exact squares.

The irregular border on the top-right corner should not be there I think.

I've thought about using Tikz, but I have no idea of how to approach this... I've searched this site for hints on how to create notebook templates and from there I would've tweaked but found nothing. I've searched some sort of starting point on Texample.net too, but nothing that I could make use of.

I wish I could provide a MWE but here the point is not that I can't make something work, but rather that I have no idea what that something could be.

Alenanno
  • 37,338

5 Answers5

12

A solution with \leaders.

  • The boxes are exact squares.
  • Equal margins.

Configuration:

  • \cellunit: width/height of a cell
  • \fboxrule: line width of the frame lines
  • \hnum: number of cells in horizontal direction
  • \vnum: number of cells in vertical direction
  • color setting
  • paper size

The example uses a grid of 10 x 20 cells (= 200 cells).

\documentclass[a4paper]{article}

\usepackage{xcolor} % fixes \fbox

\pagestyle{empty} % no page number

\setlength{\topskip}{0pt} % we do not have text lines
\setlength{\maxdepth}{0pt}

\setlength{\fboxsep}{0pt}

\newlength{\cellunit}
\newlength{\cellsep}

%%% configuration begin %%%
\setlength{\fboxrule}{.8pt} % line width of the frame lines
\setlength{\cellunit}{13mm} % width and height of the cell excluding frame
\newcommand*{\hnum}{10} % number of cells, horizontal direction
\newcommand*{\vnum}{20} % number of cells, vertical direction
\color[RGB]{50,100,200}
%%% configuration end %%%

\newcommand*{\cell}{%
  \fbox{%
    \rule{0pt}{\cellunit}%
    \rule{\cellunit}{0pt}%
  }%
}

% calculate the vertical margin
\fboxrule=2\dimexpr.5\fboxrule\relax % even sp number
\newlength{\margin}
\margin=.5\dimexpr\paperheight-\vnum\cellunit-\vnum\fboxrule-\fboxrule\relax

\ifdim\margin<0pt
  \errmessage{Cell dimensions or cell numbers are too large for the page}%
\fi

% set equal margins everywhere
\usepackage[margin=\margin]{geometry}

\begin{document}
\vbox to \textheight{%
  \kern.5\fboxrule
  \cleaders\vbox{%
    \kern-.5\fboxrule
    \hbox to \textwidth{%
      \cellsep=\dimexpr(
        \textwidth-\hnum\dimexpr\cellunit+2\fboxrule\relax   
      )/\numexpr\hnum-1\relax\relax
      \kern-.5\cellsep   
      \xleaders\hbox{%
        \kern.5\cellsep
        \cell
        \kern.5\cellsep   
      }\hskip\dimexpr\textwidth+\cellsep\relax
      \kern-.5\cellsep
    }%
    \kern-.5\fboxrule
  }\vskip\dimexpr\textheight-\fboxrule\relax
  \kern.5\fboxrule 
}%
\end{document}

Result

Heiko Oberdiek
  • 271,626
9

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{fp}

% user defined macros
\FPeval\Width{21.0}     % paper width
\FPeval\Height{29.7}    % paper height
\FPeval\HM{1}           % horizontal margin
\FPeval\Gap{0.7}        % column gap
\FPeval\M{10}           % number of columns

% auxiliary macros
\FPeval\Side{round((Width-Gap*(M-1)-2*HM)/M:2)}
\FPeval\N{round((Height-2*HM)/Side:0)}
\FPeval\VM{round((Height-N*Side)/2:2)}

\SpecialCoor
\begin{document}
\begin{pspicture}[showgrid=false](\Width,-\Height)
    \multips(0,0)(0,-\Side){\N}{\multips(\HM,-\VM)(!\Side\space \Gap\space add 0){\M}{\psframe[dimen=middle](0,0)(\Side,-\Side)}}
\end{pspicture}
\end{document}

Animated version:

The scientific law: the smaller the column gap, the fewer the number of rows.

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{fp}
\SpecialCoor
\usepackage{multido}
\begin{document}
\multido{\n=0.0+0.2}{10}{%
\FPeval\Width{21.0}
\FPeval\Height{29.7}
\FPeval\HM{1}
\FPeval\Gap{\n}
\FPeval\M{10}
\FPeval\Side{round((Width-Gap*(M-1)-2*HM)/M:2)}
\FPeval\N{round((Height-2*HM)/Side:0)}
\FPeval\VM{round((Height-N*Side)/2:2)}
\begin{pspicture}[showgrid=false](\Width,-\Height)
    \multips(0,0)(0,-\Side){\N}{\multips(\HM,-\VM)(!\Side\space \Gap\space add 0){\M}{\psframe[dimen=middle](0,0)(\Side,-\Side)}}
\end{pspicture}}
\end{document}

Edit based on Doctor Kumar's comment

For those who use pdflatex or xelatex on Windows, compile the following with -shell-escape switch. I don't like auto-pst-pdf because of my personal preference.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{GenkoYoshi.tex}
\documentclass[pstricks]{standalone}
\usepackage{fp}

% user defined macros
\FPeval\Width{21.0}     % paper width
\FPeval\Height{29.7}    % paper height
\FPeval\HM{1}           % horizontal margin
\FPeval\Gap{0.7}        % column gap
\FPeval\M{10}           % number of columns

% auxiliary macros
\FPeval\Side{round((Width-Gap*(M-1)-2*HM)/M:2)}
\FPeval\N{round((Height-2*HM)/Side:0)}
\FPeval\VM{round((Height-N*Side)/2:2)}

\SpecialCoor
\begin{document}
\begin{pspicture}[showgrid=false](\Width,-\Height)
    \multips(0,0)(0,-\Side){\N}{\multips(\HM,-\VM)(!\Side\space \Gap\space add 0){\M}{\psframe[dimen=middle](0,0)(\Side,-\Side)}}
\end{pspicture}
\end{document}
\end{filecontents*}

\begin{document}
\immediate\write18{latex GenkoYoshi}
\immediate\write18{dvips GenkoYoshi}
\immediate\write18{ps2pdf GenkoYoshi.ps}
% begin cleaning
% The following codes are written with Windows' shell commands only for Windows user.
% If you use Linux, then ask other people to translate the codes to Linux's equivalent. 
% If you have no friend who can help you, just comment the code and manually remove the associated files.
\makeatletter
\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del GenkoYoshi.\x}}
\makeatother
% end cleaning
Done\ldots\ please open the generated GenkoYoshi.pdf!
\end{document}
  • Thank you! I added a detail to my question. The squares should be exact squares... Thanks and sorry for the trouble! – Alenanno Nov 13 '12 at 19:39
  • 1
    @Alenanno: The requested feature has been implemented. – kiss my armpit Nov 13 '12 at 19:56
  • @GarbageCollector: Well now your user name is readable. Thanks for that. I have a request. Please add \usepackage{auto-pst-pdf} or its latest counterpart (I don't remember it) as a default (since you are a pstricks expert) so that we, who use pdflatex, can directly compile it. +1. –  Nov 14 '12 at 00:14
  • I tried your code but it says "Undefined control sequence" on line 19 in the first code: \multips(0,0)(0,-\Side){\N}{\multips(\HM,-\VM)(!\Side\space \Gap\space add 0){\M}{\psframe[dimen=middle](0,0)(\Side,-\Side)}}. What could it be? – Alenanno Nov 17 '12 at 12:58
  • @Alenanno: Did you compile it with pdflatex? – kiss my armpit Nov 17 '12 at 14:00
  • @GarbageCollector Yes. – Alenanno Nov 17 '12 at 14:28
  • @Alenanno: Let filename.tex be the name for the file containing the last code snippet above. Use Windows machine and compile it with pdflatex -shell-escape filename. – kiss my armpit Nov 17 '12 at 14:55
  • @GarbageCollector What if I don't have a Windows machine? :P – Alenanno Nov 17 '12 at 15:04
  • @Alenanno: See the last code's comment. You need to comment the cleaning codes. – kiss my armpit Nov 17 '12 at 15:33
  • @GarbageCollector Thanks for the contribution and help anyways. In the end I decided to accept the other answer even if your code was much shorter. :) – Alenanno Nov 17 '12 at 16:20
  • 1
    @Alenanno: I am crying... :-( – kiss my armpit Nov 17 '12 at 16:33
7

Try this using tabular. You can adjust the spacing to match your needs.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\pagestyle{empty}
\newcommand{\sss}{.2in}
\newcommand{\vvv}{.14in} % Note: This needs to be 70% of the \sss value
\newcommand{\hgt}{\rule{0pt}{\vvv}}
\newcommand{\ccc}{%
\begin{tabular}{|p{\sss}|}\hline 
\\\hgt \\\hline  \\\hgt \\\hline  \\\hgt \\\hline \\\hgt \\\hline   \\\hgt \\\hline 
\\\hgt \\\hline  \\\hgt \\\hline  \\\hgt \\\hline \\\hgt \\\hline   \\\hgt \\\hline 
\\\hgt \\\hline  \\\hgt \\\hline  \\\hgt \\\hline \\\hgt \\\hline   \\\hgt \\\hline 
\\\hgt \\\hline  \\\hgt \\\hline  \\\hgt \\\hline \\\hgt \\\hline   \\\hgt \\\hline 
\\\hgt \\\hline  \\\hgt \\\hline  \\\hgt \\\hline \\\hgt \\\hline   \\\hgt \\\hline 
\end{tabular}}
\begin{document}
\ccc\quad \ccc\quad \ccc\quad \ccc\quad \ccc\quad 
\ccc\quad \ccc\quad \ccc\quad \ccc\quad \ccc\quad 
\end{document}

enter image description here

6

Here is a TikZ solution. The \genkoyoshi command uses four parameters: maxrow, maxcol, size (of exact square), sep (distance between two columns).

You can use the geometry package to change the margins.

enter image description here

\documentclass{article}
\usepackage{tikz}
\pagestyle{empty}
\newcommand\genkoyoshi[4]{% maxrow, maxcol, size, sep
  \def\maxrow{#1}%
  \def\maxcol{#2}%
  \def\size{#3}%
  \def\sep{#4}%
  \begin{tikzpicture}
    \pgfmathsetmacro{\inc}{\size+\sep}
    \foreach \col in {1,...,\maxcol}{
      \foreach \row in {1,...,\maxrow}{
        \draw ({(\col-1)*\inc pt},{\row*\size})
        rectangle ++ (\size,\size);
      }
    }
  \end{tikzpicture}%
}
\begin{document}
\genkoyoshi{24}{11}{8mm}{2mm}
\end{document}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283
3

Here's another tikz solution using matrix of nodes

The clever part of the code has shamelessly been stolen from

Tikz foreach inside matrix

screenshot

You can change the number of rows, columns, and column separation easily to suit your needs.

\documentclass{article}
\usepackage[paper=a4paper, showframe=true]{geometry}
\usepackage{etoolbox}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\let\mymatrixcontent\empty
\newcommand{\row}{%
  \foreach \j in {1,...,25}{
    \foreach \i in {1,...,10} {%
      \begingroup\edef\x{\endgroup
      \noexpand\gappto\noexpand\mymatrixcontent{ {}\&}}\x
      }%
    \gappto\mymatrixcontent{\\}%
  }
}
\row

\begin{tikzpicture}
\tikzset{every node/.style={minimum size=8mm},
  pre/.style={draw}}
  \matrix (a) [ampersand replacement=\&,matrix of math nodes, nodes={pre},column sep=6mm]{
    \mymatrixcontent
  };
\end{tikzpicture}

\end{document}
cmhughes
  • 100,947