Kodama's home / tips.

LaTeXの縁つき行列.

TeX の \bordermatrix 風に縁をつけられる LaTeX コマンドとして \borderarray を作ってみました.

TeX の bordermatrix だと, 行列中に区切り線を入れるのが面倒なので, LaTeX の array 環境風に使えるものを作ってみた. 実際には, array 環境にパラメ−タをわたして, 括弧をずらして書き込んでいるだけなので, array 環境とほぼ同様に使える. 場当り的に作ったマクロだけど, とりあえず使えるから, まあ, 良いでしょう.

使用例:

$
\borderarray{[}{]}{1em}{1.2ex}{cccc}{
0 & 1 & 2 & 3 \\
1 & a & b & c \\
2 & d & e & f \\
3 & g & h & i
}
$
$
\borderarray{(}{)}{1em}{1.2ex}{cccc}{
0 & 1 & 2 & 3 \\
1 & a \,\vline & b & c \\ \cline{2-4}
2 & d \,\vline & e & f \\
3 & g \,\vline & h & i
}
$

\newcommand{\bigzero}{{\hbox{\Large 0\rule{0em}{2ex}}}} %
\newcommand{\bigzeroU}{{\lower2ex\hbox{\Large 0}}} % for upper matrix
\newcommand{\bigzeroL}{{\lower-.1ex\hbox{\Large 0}}} % for lower matrix
\newcommand{\bigstar}{{\lower0.7ex\hbox{\Large *}}} %
$
\borderarray{(}{)}{2em}{1.2ex}{cccccccccccccccc}{
  &a_{11}&\dots&a_{1p_1}&&b_{11}&\dots&b_{1p_1}&&{\bf a_2}&&{\bf b_2}&&\dots&&{\bf c}\\
a_{11}&1-t& &\bigzeroU &\vline&-t& &\bigzeroU&\vline& &\vline& &\vline& &\vline& \\
\vdots& &\ddots& &\vline& &\ddots& &\vline&\bigzero&\vline&\bigzero&\vline&\bigzero&\vline& \bigzero\\ 
a_{1p_1}&\bigzeroL & &1-t&\vline&\bigzeroL& &-t&\vline& &\vline& &\vline& &\vline&\\\cline{2-16}
%
b_{11}&1& &\bigzeroU&\vline& & & &\vline& &\vline& &\vline& &\vline& \\
\vdots & &\ddots& &\vline& &\bigstar& &\vline&\bigzero&\vline&\bigstar&\vline&\dots&\vline&\bigzero\\
b_{1p_1}&\bigzeroL& &1&\vline& & & &\vline& &\vline& &\vline& &\vline& \\\cline{2-16}
%
{\bf a_2}& &\bigzero & &\vline& &\bigzero & &\vline& &\vline& &\vline& &\vline&\bigzero \\\cline{2-16}
{\bf b_2}& &\bigzero & &\vline& &\bigstar & &\vline& &\vline& &\vline& &\vline&\bigzero \\\cline{2-16}
\vdots& &\bigzero & &\vline& &\vdots& &\vline& &\vline&&\vline&&\vline& \bigzero\\\cline{2-16}
{\bf c}& &\bigzero & &\vline& &\bigzero  & &\vline&\bigzero &\vline&\bigzero &\vline&\bigzero &\vline&\bigzero 
}
$

以下のコ−ドを LaTeX のソ−ス中に組み込んでつかう.

\def\borderarray#1#2#3#4#5#6{%
% \borderarray is a simple imitation of bordermatrix using array.
% borderarray. 2001-02-24 K.Kodama
% #1: left ({[, #2:right )}]
% #3: width of border, #4: height of border,
% #5: same as PREAMBLE for array, #6: body for array 
\setbox0\hbox{$\begin{array}{#5}#6\end{array}$}
\setlength{\dimen1}{\wd0}\addtolength{\dimen1}{-#3}\addtolength{\dimen1}{-\arraycolsep}
\setlength{\dimen2}{\ht0}\addtolength{\dimen2}{-#4}
\setbox1\hbox{$\left#1\rule{\dimen1}{0pt}\rule{0pt}{\dimen2}\right#2$}
\setbox0\hbox{\raisebox{\dp0}{\box0}\kern-\dimen1\kern-5pt\raisebox{\dp1}{\box1}}
\vcenter{\box0}
}

細かい位置決めは 3,4番目のパラメ−タの調整が必要. 本来ならこれを内部で計算させるべきだが面倒なので作っていない. 簡単に計算する方法ってある? 一旦 array で作った行列の塊から, 左の幅と, 上の高さを取り出すと良いけど, どうやって切り出すの?


Kodama's home / tips.