1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

LaTeX で日本語を均等割り付けする方法

Last updated at Posted at 2020-07-27

LaTeX で日本語を均等割り付けするマクロを作製しました。

\kintou{x}{文字列} で文字列をx字に均等割り付けします。
\kintouwidth{dim}{文字列} が実際に長さdimに文字列を均等割付し、
\kintou は内部で \kintouwidth{x\zw}{文字列} を呼ぶだけです。

LuaLaTeX 用に作ったので、それ以外のエンジンを用いる場合は \zw の代わりにzwを用いてください。
英文字も文字ごとに均等割り付けしたい場合は
\kintou{5}{A B C D}のように1文字ごとに半角スペースを入れてください。

スクリーンショット 2020-07-27 16.37.48.png

\documentclass[b5paper,10pt]{ltjsarticle}

\usepackage{calc}
\usepackage{ifthen}
\usepackage{graphicx}

\makeatletter
\newlength{\wtarget}
\newlength{\wactual}
\newcommand*{\kintou}[2]{\kintouwidth{#1\zw}{#2}}
\newcommand*{\kintouwidth}[2]{%
    \setlength{\wtarget}{#1}%
    \settowidth{\wactual}{#2}%
    \ifthenelse{\lengthtest{\wtarget < \wactual}}{%
        \setlength{\wtarget}{1pt * \real{\strip@pt\wtarget} / \real{\strip@pt\wactual}}%
        \scalebox{\strip@pt\wtarget}[1]{#2}%
    }{%
        \makebox[\wtarget][s]{#2}%
    }%
}
\makeatother

\begin{document}

\begin{tabular}{ll}
\makebox[5\zw][s]{\textleftarrow\ 5字 \textrightarrow}
& \makebox[2cm][s]{\textleftarrow\ 2cm \textrightarrow}\\
\kintou{5}{寿限無寿限無五劫の擦り切れ} & \kintouwidth{2cm}{寿限無寿限無五劫の擦り切れ}\\
\kintou{5}{寿限無寿限無五劫} & \kintouwidth{2cm}{寿限無寿限無五劫}\\
\kintou{5}{寿限無寿限} & \kintouwidth{2cm}{寿限無寿限}\\
\kintou{5}{寿限無} & \kintouwidth{2cm}{寿限無}\\
\kintou{5}{寿限} & \kintouwidth{2cm}{寿限}\\
\end{tabular}

\end{document}

パッケージにしたもの。

kinto.sty
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{kintou}[2020/07/27 Kintou waritsuke Package]

\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage{graphicx}

\makeatletter
\newlength{\wtarget}
\newlength{\wactual}
\newcommand*{\kintou}[2]{%
    \ifthenelse{\isundefined{\zw}}{\kintouwidth{#1zw}{#2}}{\kintouwidth{#1\zw}{#2}}%
}
\newcommand*{\kintouwidth}[2]{%
    \setlength{\wtarget}{#1}%
    \settowidth{\wactual}{#2}%
    \ifthenelse{\lengthtest{\wtarget < \wactual}}{%
        \setlength{\wtarget}{1pt * \real{\strip@pt\wtarget} / \real{\strip@pt\wactual}}%
        \scalebox{\strip@pt\wtarget}[1]{#2}%
    }{%
        \makebox[\wtarget][s]{#2}%
    }%
}
\makeatother

\endinput

1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?