Chapter 20 Tables
<sidebyside>, getting tables to lay out consistently between HTML and PDF is probably the second biggest headache that PreTeXt takes care of for us behind the scenes. Considerable effort has been taken in order to fix some of the challenges inherent to working with the
tabular environment in LaTeX, and so if you author in PreTeXt, you should be able to forget the hacks you had to learn to make nice tables in LaTeX.
Tables should only be used to display data. Too often in other authoring systems, tables are used as a crutch to facilitate the visual layout of a page. Do not do that when authoring PreTeXt. A good question to ask yourself before using a
<tabular> is “Do the \(xy\)-coordinates of a cell have semantic meaning in terms of my data?” If the answer is “yes”, then make an array of numbers with
<tabular>. If not, find a more suitable tag. (Perhaps
<sbsgroup>.) One of the many reasons for this is that screen readers used by individuals with visual impairments read tables in a very specific way that assumes the \(xy\)-coordinates of each cell are contributing to the meaning. Individuals who use screen readers will find a document that uses tables to do something other than present tabular data very confusing and frustrating.
Similar to LaTeX, PreTeXt provides a
<table> tag and a
<tabular> tag. The
<tabular> tag is used for producing the array of data, while the
<table> tag provides the number and title.
The code in Listing 20.0.1 produces the following output:
|Conjunction \(x\wedge y\)
|Disjunction \(x\vee y\)
<image>, you can use
<tabular> on its own to lay out a table of data, centered on a line, between (for instance) a couple of
<p> elements. In many cases, the sort of data layout generated using
<tabular> functions more as a figure than a table according to the definitions in the Chicago Manual of Style  (CMOS), which PreTeXt attempts to follow in the absence of other guiding principles. The quote below from David Farmer on the pretext-dev Google Group
provides guidance on deciding if your
<tabular> should be contained in
“There is an entire chapter on tables in CMOS, so I’ll try to summarize how those are distinct from many uses of grids of numbers in PreTeXt. Some approximate quotes about tables from CMOS:
- facts that are easy to scan and compare
- a reader unfamiliar with the material should still be able to make sense of the table
- tables are numbered and have titles (and not captions)My take-away is that a CMOS table is a supplement to what is written in the text and at any one time only a small amount of the table is relevant. Rephrasing: a CMOS table is not intended to be integrated with the narrative of the book, and the reader is not supposed to pore over a large fraction of the table when it is first encountered.”―David Farmer
In reality, the
<tabular> in Listing 20.0.1 really should be contained in
<figure> (and then the
<title> must become a
<caption>). Perhaps someday we will come up with an example
<tabular> that meets the CMOS definition of a table to use instead.
See Section 4.18 for more information about how to make more complicated tables including formatting columns and vertical and horizontal rules.