dcolumn, Książki, TeX, Dokumentacja pakietów i narzędzi
[ Pobierz całość w formacie PDF ]
Thedcolumnpackage
DavidCarlisle
2001/05/28
Abstract
Thispackagedefinesasystemfordefiningcolumnsofentriesinan
array
or
tabular
whicharetobealignedona‘decimalpoint’.
Thispackagedefines
D
tobeacolumnspecifierwiththreearguments.
D{
hsep.texi
}{
hsep.dvii
}{
hdecimalplacesi
}
hsep.texishouldbeasinglecharacter,thisisusedastheseparatorinthe
.tex
file.Thusitwillusuallybe‘
.
’or‘
,
’.
hsep.dviiisusedastheseparatorintheoutput,thismaybethesameasthe
firstargument,butmaybeanymath-modeexpression,suchas
\cdot
.Itshouldbe
notedthat
dcolumn
alwaysusesmathmodeforthedigitsaswellastheseparator.
hdecimalplacesishouldbethemaximumnumberofdecimalplacesinthe
column.Ifthisisnegative,anynumberofdecimalplacescanbeusedinthe
column,andallentrieswillbecentredon(theleadingedgeof)theseparator.Note
thatthiscancauseacolumntobetoowide,comparethefirsttwocolumnsinthe
examplebelow.Ifthisargumentispositive,thecolumnusesmacrosequivalentto
\rightdots\endrightdots
of
array.sty
,otherwisethemacrosareessentially
equivalentto
\centerdots\endcenterdots
.
Youmaynotwanttouseallthreeentriesinthe
array
or
tabular
preamble,
soyoumaydefineyourownpreamblespecifiersusing
\newcolumntype
.
Forexamplewemaysay:
\newcolumntype{d}[1]{D{.}{\cdot}{#1}}
d
takesasingleargumentspecifyingthenumberofdecimalplaces,andthe
.tex
fileshoulduse
.
,with·beingusedintheoutput.
\newcolumntype{.}{D{.}{.}{-1}}
.
specifiesacolumnofentriestobecentredonthe
.
.
\newcolumntype{,}{D{,}{,}{2}}
,
specifiestakesacolumnofentrieswithatmosttwodecimalplacesaftera
,
.
Thefollowingtablebegins
\begin{tabular}{|d{-1}|d{2}|.|,|}
Thisfilehasversionnumberv1.06,lastrevised2001/05/28.
1
1·2 1·2 1
.
2 1
,
2
1·23 1·23 12
.
5 300
,
2
1121·2 1121·2 861
.
20 674
,
29
184 184 10 69
·4 ·4
,
4
.
4
Notethatthefirstcolumn,whichhadanegativehdecimalplacesiargumentis
widerthanthesecondcolumn,sothatthedecimalpointappearsinthemiddle
ofthecolumn.Alsonotethatthispackagedealscorrectlywithentrieswithno
decimalpart,nointegerpart,andblankentries.
Ifyouhavetableheadings(insertedwith
\multicolumn{1}{c}{..}
toover-
ridethe
D
columntype)thenitmaybethatneitheroftheabove‘centred’or‘right
aligned’formsisquitewhatyouwant.
head head head
1.2 1.2 1.2
11212.2 11212.2 11212.2
.4 .4 .4
wideheadingwideheadingwideheading
1.2 1.2 1.2
.4 .4 .4
Inbothofthesetablesthefirstcolumnissetwith
D{.}{.}{-1}
toproduce
acolumncenteredonthe
.
,andthesecondcolumnissetwith
D{.}{.}{1}
to
producearightalignedcolumn.
Thecenteredcolumnproducescolumnsthatarewiderthannecessarytofitin
thenumbersunderaheadingasithastoensurethatthedecimalpointiscentred.
Therightalignedcolumntwodoesnothavethisdrawback,butunderawide
headingacolumnofsmallrightalignedfigureslooksabitodd.
Inversionv1.03athirdpossibilityisintroduced.Thethirdhdecimalplacesi
argumentmayspecifyboththenumberofdigitstotheleftandtotherightofthe
decimalplace.Thethirdcolumninthefirsttableaboveissetwith
D{.}{.}{5.1}
andinthesecondtable,
D{.}{.}{1.1}
,tospecify‘fiveplacestotheleftandone
totheright’and‘oneplacetotheleftandonetotheright’respectively.(You
mayuse‘,’orothertokens,notnecessarily‘.’inthisargument.)Thecolumnof
figuresisthenpositionedsuchthatanumberwiththespecifiednumbersofdigits
iscentredinthecolumn.
Thisnotationalsoenablescolumnsthatarecentredonthemid-pointofthe
separator,ratherthanitsleadingedge;forexample
D{+}{\,\pm\,}{3,3}
willgive
nice,symmetriclayoutofuptothreedigitsoneithersideofa±sign.
1TheMacros
1
hpackagei
Firstweload
array.sty
ifitnotalreadyloaded.
2
\RequirePackage{array}
Thebasicideasbehindthesemacrosareexplainedinthedocumentationfor
array.sty
.Howevertheyusethreetrickswhichmaybeusefulinothercontexts.
2
•Theseparatorissurroundedinextra
{}
,sothatitissetwith
\mathord
spacing,otherwise,forinstancea‘,’wouldhaveextraspaceafterit.
•Theseparatorisnotgivenitsspecialdefinitionbymakingitactive,asthis
wouldnotworkforanentrysuchas
&.5&
,asthefirsttokenofanalignment
entryisreadbeforethepreamblepart,incaseitisan
\omit
,inwhichcase
thepreambleistobeomitted.Insteadweswitchthemathcodeto(hex)
8000,whichmakesthetokenactasifitwereactive.
•Although
\mathcode‘.="8000
makes
.
actasifitwereactive,itisstillnot
allowedinconstructionssuchas
\def.{}
,eveninmath-mode,sowehave
toconstructanactiveversionoftheseparator,thisisdonebymakingitthe
uppercaseof
~
,andthenusingtheconstruct
\uppercase{\def~}{
hdefinitioni
}
.
Notethatthehdefinitioniisnotuppercased,sothedefinitioncanreferto
thestandard,non-activeuseoftheseparator.
\DC@
Setupuppercasetablesasrequired,andthengrabthefirstpartofthenumerical
argumentinto
\count@
.
3
\def\DC@#1#2#3{%
4
\uccode‘\~=‘#1\relax
5
\m@th
6
\afterassignment\DC@x\count@#3\relax{#1}{#2}}
\DC@x
If
\count@
isnegative,centreonthedecimalpoint.Ifitispositiveeither
#1
will
beemptyinwhichcasebadoutdecimalparttothenumberofdigitsspecified
by
\count@
or(newfeatureinv1.03)itisnoneemptyinwhichcase
\count@
containsthenumberofdigitstotheleftofthepoint,and
#1
containsajunktoken
(probably
.
)followedbythenumberofdigitstotherightofthepoint.Ineither
oftheselattercases,
\DC@right
isused.
7
\def\DC@x#1\relax#2#3{%
8
\ifnum\z@>\count@
9
\expandafter\DC@centre
10
\else
11
\expandafter\DC@right
12
\fi
13
{#2}{#3}{#1}}
\DC@centre
Ifcenteringonthedecimalpoint,justneedtoboxupthetwohalves.
14
\def\DC@centre#1#2#3{%
15
\let\DC@end\DC@endcentre
16
\uppercase{\def~}{$\egroup\setbox\tw@=\hbox\bgroup${#2}}%
17
\setbox\tw@=\hbox{${\phantom{{#2}}}$}%
18
\setbox\z@=\hbox\bgroup$\mathcode‘#1="8000}
\DC@endcentre
andthenpadoutthesmallerofthetwoboxessothereisthesameamountofstu
eithersideofthepoint.
19
\def\DC@endcentre{$\egroup
3
20
\ifdim\wd\z@>\wd\tw@
21
\setbox\tw@=\hboxto\wd\z@{\unhbox\tw@\hfill}%
22
\else
23
\setbox\z@=\hboxto\wd\tw@{\hfill\unhbox\z@}\fi
24
\box\z@\box\tw@}
\DC@right
Thisdealswithboththecaseswhereaspecifiednumberofdecimalplacesisgiven.
25
\def\DC@right#1#2#3{%
26
\ifx\relax#3\relax
If
#3
isempty,add
\hfill
torightalignthecolumn,andJustset
\DC@rl
tobegin
agroup,sonothingfancyisdonewiththewholenumberpart.
27
\hfill
28
\let\DC@rl\bgroup
29
\else
Otherwiseset
\DC@rl
sothatthewholenumberpartisputinabox
\count@
timesaswideasadigit.Inordertosharecodewiththeotherbranch,thenmove
#3
(thenumberofdecimalplaces)into
\count@
throwingawaythe‘.’fromthe
usersyntax.
30
\edef\DC@rl{to\the\count@\dimen@ii\bgroup\hss\hfill}%
31
\count@\@gobble#3\relax
32
\fi
33
\let\DC@end\DC@endright
Box2containsthedecimalpart,setto
\dimen@
whichiscalculatedbelowtobe
\count@
timesthewidthofadigit,plusthewithofthe‘decimalpoint’.
34
\uppercase{\def~}{$\egroup\setbox\tw@\hboxto\dimen@\bgroup${#2}}%
35
\setbox\z@\hbox{$1$}\dimen@ii\wd\z@
36
\dimen@\count@\dimen@ii
37
\setbox\z@\hbox{${#2}$}\advance\dimen@\wd\z@
38
\setbox\tw@\hboxto\dimen@{}%
Box0containsthewholenumberpart,eitherjustatitsnaturalsizeforright
alignedcolumns,orsetto(theoldvalueof)
\count@
timesthewidthofadigit.
\DC@rl
definedabovedeterminesthetwocases.
39
\setbox\z@\hbox\DC@rl$\mathcode‘#1="8000}
\DC@endright
Justfinishothesecondbox,andthenputoutbothboxes.
40
\def\DC@endright{$\hfil\egroup\box\z@\box\tw@}
D
Theuserinterface,definethe
D
columntotakethreearguments.Forspecial
purposes,youmayneedtodirectlyaccess
\DC@
ratherthanthe
D
column,egto
getaboldversionyoucoulduse
\newcolumntype{E}[3]{>{\boldmath\DC@{#1}{#2}{#3}}c<{\DC@end}}
41
\newcolumntype{D}[3]{>{\DC@{#1}{#2}{#3}}c<{\DC@end}}
42
h/packagei
4
[ Pobierz całość w formacie PDF ]