1. XeLaTeX
For XeLaTeX, the document should be saved in UTF-8 encoding.
1.1. xeCJK
package
I advice you to use XeLaTeX with package xeCJK
. An example:
\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{MS Mincho} % for \rmfamily
\setCJKsansfont{MS Gothic} % for \sffamily
\begin{document}
\section{日本語}
お早う
\textsf{こんにちわ}
\end{document}
See manual of xeCJK
and fontspec
for more information.
Chinese and Korean work the same. In fact, xeCJK
is originally designed for Chinese by Prof. 孙文昌.
xeCJK
: http://mirrors.ctan.org/macros/xetex/latex/xecjk/xeCJK.pdf
fontspec
: http://mirrors.ctan.org/macros/latex/contrib/fontspec/fontspec.pdf
1.2. zxjatype
package
zxjatype
internally calls xeCJK
, with some configurations for Japanese. You can also use zxjafont
package to use some predefined fonts. It is easier to use compared to raw xeCJK
. An example:
\documentclass{article}
\usepackage{zxjatype}
\usepackage[ipa]{zxjafont}
\begin{document}
\section{日本語}
お早う
\textsf{こんにちわ}
\end{document}
zxjatype
: http://zrbabbler.sp.land.to/zxjatype.html
1.3. bxjsclasses
with zxjatype
bxjsclasses
bundle provides some Japanese local classes. It can be used with different TeX engines.
\documentclass{bxjsarticle}
\usepackage{zxjatype}
\usepackage[ipa]{zxjafont}
\begin{document}
\section{日本語}
お早う
\textsf{こんにちわ}
\end{document}
2. LuaLaTeX
For LuaLaTeX, the document should be saved in UTF-8 encoding.
2.1. luatexja-fontspec
package in luatexja
bundle
luatexja
bundle provides Japanese support for LuaTeX. A simple LaTeX example:
\documentclass{article}
\usepackage{luatexja-fontspec}
\setmainjfont{MS Mincho} % \mcfamily
\setsansjfont{MS Gothic} % \gtfamily
\begin{document}
\section{日本語}
お早う
\textgt{こんにちわ}
\end{document}
2.2. ltjsclasses
classes in luatexja
bundle
ltjsclasses
provides some Japanese document classes for convenience. An example:
\documentclass{ltjsarticle}
\usepackage{luatexja-fontspec}
\setmainjfont{MS Mincho} % \mcfamily
\setsansjfont{MS Gothic} % \gtfamily
\begin{document}
\section{日本語}
お早う
\textgt{こんにちわ}
\end{document}
3. upLaTeX + ujclasses
upLaTeX is a Japanese TeX format. It needs UTF-8 encoding.
An example:
\documentclass{ujarticle}
\begin{document}
\section{日本語}
お早う
\textgt{こんにちわ}
\end{document}
Compile with
uplatex foo.tex
dvipdfmx foo.dvi
4. pLaTeX + jsclasses
(Relatively Old)
pLaTeX is a Japanese TeX format. Documents should be saved in SJIS encoding. Documentation in English is available here.
An example:
% SJIS encoding
\documentclass{jsarticle}
\begin{document}
\section{日本語}
お早う
\textgt{こんにちわ}
\end{document}
Compile with
pdfplatex foo.tex
or
platex foo.tex
dvipdfmx foo.dvi
5. CJK
package (Obsolete)
Older CJK
package is still useful. It works well with PDFLaTeX and LaTeX (Dvips, dvipdfmx). If the document has only a few wide characters, CJK
package may be a reasonable choice with better compatibility.
Be sure you have installed the proper CJK fonts for CJK
package. Typically, this is not done. TeX Live and MiKTeX have a wadalab
package, install it when necessary. (Also ipaex
and ipaex-type1
) Then you can use:
% UTF-8 encoding
\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{min}
\section{日本語}
お早う
{\CJKfamily{goth} こんにちわ}
\clearpage\end{CJK*}
\end{document}
See $TEXMF/tex/latex/cjk/texinput/UTF8/c70*.fd
, $TEXMF/tex/latex/cjk/contrib/wadalab/c70*.fd
, etc. for pre-installed CJK font families. Frankly speaking, these free Type1 CJK fonts are not very good. It is better to install the fonts yourself.
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}
Best Answer
Here you go. My code is a mild extension of this answer by Paul Gaborit.
Code
Comments on the code
The list
100,66,33,0,0,0,0,0,0,0
gives the opacity of each row -- 0 is transparent, and 100 is completely black. The length of that list gives the number of rows, hence the0
fillers at the end.The list
a,b,c,d,e,f,g,h,i,j,k
gives the character you want in each column.The
8mm
is the height and width of each cell, and the2mm
is the size of the gap between columnsThe notation
black!40
gives a colour that is 40% black and 60% white.Each letter is centred horizontally and vertically in its cell, which is why the
g
looks a bit high and thed
looks a bit low. If you don't like this, change{\colname}
on line 20 to{\strut\colname}
.Result