What is the difference between a tabular and an array environment? When should be used the former and when the latter?
2 Answers
The array
environment is for math mode
and cell contents will be typeset in math mode (textstyle
by default) and tabular
is for text mode
.
While array requires being in math mode, the tabular
environment can be used in math mode
, and its contents will be typeset in text mode
. Inside an array
, the p, m or b specifiers also switch cell contents to text mode.
-
3
-
1@egreg: Yes, of course, but I focused on the main stream of the question. I'll add it, though, as it can be explained in a few words.– BernardOct 6, 2014 at 21:14
-
@user257651: they said I was aggressive, because there's an anonymous downvoter, which gives no explanation of his downvotes, and that I dared call a ‘troll’.– BernardDec 15, 2021 at 21:01
Environments such as
tabular
,tabular*
,tabularx
,tabulary
, andlongtable
-- hereafter,tabular
-like environments -- should be used if much of the material they contain should be typeset in text mode. (Note that having numbers in a table does not automatically mean it's necessary to typeset the numbers in math mode.) The material formatted by thel
,c
,r
,p
, andm
column types is expected to be in text mode.It is possible, of course, to have math-mode material in a
tabular
-like environment. You'll just need to encase the math material in$
switches like you would in ordinary mode. You could also use a specialized column type -- such as theD
column type of thedcolumn
package and theS
column type of thesiunitx
package -- that treats its contents as being in math mode by default. (ForD
andS
columns, you'll need to provide overrides for material that should not be be typeset in math mode.)The
array
environment is meant to be used in a math environment, and LaTeX treats the contents ofl
,c
, andr
columns -- but not ofp
columns! -- as being in math mode unless you do something to override this setting. If most of the table's material is going to be in math mode, it's preferable to use anarray
instead of atabular
-like environment: if nothing else, you'll save yourself from having to type a lot of$
sumbols!The amount of intercolumn whitespace in
tabular
-like environments is given by2\tabcolsep
. Forarray
environments, the respective parameter is called\arraycolsep
. The default values of\tabcolsep
and\arraycolsep
in the main LaTeX document classes are6pt
and5pt
, respectively.There's a very important LaTeX package called array. Despite what its name might suggest, it provides all sorts of goodies for both
array
environments andtabular
-like environments. Indeed, thetabularx
package depends on and therefore automatically loads thearray
package.
-
1Your answer is great and very detailed but I have chosen Bernard's answer as it was the first to answer my question. I really appreciate it and I have upvoted, thank you.– AdamOct 6, 2014 at 20:28
array
is formath mode
and cell contents will be typeset in math mode (` textstyleby default) and
tabular` is fortext mode
.array
andtabular
: the name (and default value) of the parameter that governs the intercolumn whitespace (\tabcolsep
and\arraycolsep
).