2010/04/04

[latex] 表格小數點對齊置中欄寬 / dot(decimal point) aligned to the centerline of a table cell

\usepackage{dcolumn, array}


\newcolumntype{z}{D{.}{.}{-1}}
Defining a new command, z is as c, l, r in tabular environment. The z is replaced with D{.}{.}{-1} in tabular.
It seems like new command only can be 1 character.
D : D is the command of dcolumn
{.} : . is the character to be aligned
{.} : . is the character above to be replaced with.
-1 : centered. If it's a positive number, it represents the digits after decimal point



%% I can't solve some problems now, so the title issue is currently dealt with multicolumn%%

Define a new command

\newcommand{\mcm}[1]{\multicolumn{1}{>{\centering}m{#1}|}}
[1] : 1 parameter can be input
#1 : where the parameter be put. If there are more than one, it can be listed #1, #2 ...
{1} : to cross 1 column

>{} is the command of array, it works prior to columns be assigned.
Here \centering is the argument to make data centered in multicolumn.
But multicolumn command still makes something like box, it cannot be aligned to and
overlapped to the border of the table. It seems a little shift. \parbox or \makebox constrain
width of words but width of cells that makes words too wide and not wrap.

%%
*{6}{|z} equals to |z|z|z|z|z|z which is a trick.
z is defined above. * means repeatition {#} times.


%%
\mcm{2em}{run\\time}

It's stupid and ugly but I just can code this to define the cell of title rows.
That's because I want to make thin and tight columns. If words of titles
are in the same line, it is too wide. It has to clip word segment into several
lines to make it tighter.



-- 2008/06/24 bbs backup --
\usepackage{dcolumn, array}
給對齊小數點用的



\newcolumntype{z}{D{.}{.}{-1}}
定義新指令 之後在tabular內用z就會自動代換
新指定似乎只能用一個字元
D是dcolumn的指令
{.}表示輸入要對齊的文字
{.}表示顯示時要代換的符號
-1表示置中若是正數表示小數位數

%% 因為目前還是無解 所以先用multicolumn來處理title的部份 %%

\newcommand{\mcm}[1]{\multicolumn{1}{>{\centering}m{#1}|}}
定義新的指令
[1]表示可輸入一個參數
#1為參數的位置
若是參數很多  就依照#1 #2 這樣的順序排
{1}跨一欄

>{}是array的指令 在欄位編排之前所要加入的命令
這裡加入\centering使multicolumn置中
但因為multicolumn還是在原本的格子製造了一個類似box的東西出來
所以仍然不能和原本的格子切齊
排起來有點歪歪的
但用\parbox或\makebox則只會限制文字的寬度表格則不會
結果還是太寬   而且不會換行

*{6}{|z}

tabular原本的lrc可以用z
這樣就會使用之前定義的指令
*是重複格式
{6}{|z} 相當於 |z|z|z|z|z|z
這是表格的技巧


\mcm{2em}{run\\time}

在title內就只好用這樣子的方式指定欄寬了
想要換行的地方不需要加空白
否則空白也當作一個字元進去排


很笨的方法

%% 因為沒時間了 以後再慢慢學自己適應大小的方法吧 %%

沒有留言:

張貼留言