Tables

To make a table, you use vertical bars (|) to separate the columns of your tables. Here are a few examples.

This results in a very simple table with two columns of ingredients:

1 | 2 cups old fashioned oats          | 1 1/2 tsp vanilla              |
2 | 1 cup sunflower seeds              | 1/4 tsp salt                   |
3 | 1 cup shredded coconut             | 1/2 cup chopped pitted dates   |
4 | 1/2 cup toasted wheat germ or bran | 1/2 cup chopped dried apricots |
5 | 3 tbsp unsalted butter             | 1/2 cup dried cranberries      |
6 | 2/3 cup honey                      |                                |
7 | 1/4 cup packed brown sugar         |                                |
2 cups old fashioned oats 1 1/2 tsp vanilla
1 cup sunflower seeds 1/4 tsp salt
1 cup shredded coconut 1/2 cup chopped pitted dates
1/2 cup toasted wheat germ or bran 1/2 cup chopped dried apricots
3 tbsp unsalted butter 1/2 cup dried cranberries
2/3 cup honey  
1/4 cup packed brown sugar  

If you want the first line to be formatted as a heading, then do something like this:

1 |Verb   |Action                                          |Idempotent?|
2 |-------|------------------------------------------------|-----------|
3 |GET    |Responds with information about the resource    |Yes        |
4 |POST   |Creates a sub-resource of the resource POSTed to|No         |
5 |PUT    |Creates or updates the resource being PUT to    |Yes        |
6 |DELETE |DELETES the resource                            |Yes        |
7 |HEAD   |Gets metadata about the resource                |Yes        |
Verb Action Idempotent?
GET Responds with information about the resource Yes
POST Creates a sub-resource of the resource POSTed to No
PUT Creates or updates the resource being PUT to Yes
DELETE DELETES the resource Yes
HEAD Gets metadata about the resource Yes

Table Width

Your book has a default table-width setting. By default, it’s set to “default”, which stretches tables to 80% of the page width.

The other two settings are “narrow” and “wide”. Narrow makes the table as narrow as possible, wide makes it take up the full page width.

You can set the default table-width on the “Book Theme” tab under “Writing” in your book tools menu.

The major drawback to narrow is that we do no automatic word-wrapping in PDFs, so the table may go off the side of the page. We recommend using default or wide mode.

You can also over-ride the width of individual tables by setting a width attribute. For example, if your book had a default table width of “wide”, the table below would be narrow:

1 {width="narrow"}
2 | one | two | three |
3 |-------------------|
4 | a   | b   | c     |
5 |-------------------|
6 | d   | e   | f     |
one two three
a b c
d e f

Here it is with {width="default"}:

one two three
a b c
d e f

You can use “wide”, “default” or “narrow”, or a percentage for the width parameter. The following table would take up exactly half the page-width

1 {width="50%"}
2 | one | two | three |
3 |-------------------|
4 | a   | b   | c     |
5 |-------------------|
6 | d   | e   | f     |
one two three
a b c
d e f

Multi-line rows

Here is that table from above reformatted to be narrower by using multi-line rows. The first dashed line makes the line before it a heading. The rest of the dashed lines just result in a larger vertical gap than a plain newline.

 1 |Verb   | Action                                   |  Idempotent?   |
 2 |-------|------------------------------------------|----------------|
 3 |GET    | Responds with information about the      |  Yes           |
 4 |       | resource                                 |                |
 5 |-------|------------------------------------------|----------------|
 6 |POST   | Creates a sub-resource of the resource   |  No            |
 7 |       | being POSTed to                          |                |
 8 |-------|------------------------------------------|----------------|
 9 |PUT    | Creates or updates the resource being    |  Yes           |
10 |       | PUT to                                   |                |
11 |-------|------------------------------------------|----------------|
12 |DELETE | DELETES the resource                     |  Yes           |
13 |-------|------------------------------------------|----------------|
14 |HEAD   | Gets metadata about the resource         |  Yes           |
Verb Action Idempotent?
GET Responds with information about the Yes
  resource  
POST Creates a sub-resource of the resource No
  being POSTed to  
PUT Creates or updates the resource being Yes
  PUT to  
DELETE DELETES the resource Yes
HEAD Gets metadata about the resource Yes

IF you want to put line breaks in table cells, you can do the following:

 1 |Verb          | Action                                 |
 2 |--------------|----------------------------------------|
 3 |Multiline     | You can have multiple-lines in a       |
 4 |              | table, and line-breaks are respected.  |
 5 |              |                                        |
 6 |              | This is a second paragraph             |
 7 |-------------------------------------------------------|
 8 |continued!    | You create new table cells with a      |
 9 |              | line of dashes surrounded by pipes     |
10 |              |                                        |
11 |              | (Pipes are the vertical lines, "\|")    |
Verb Action
Multiline You can have multiple-lines in a
  table, and line-breaks are respected.
   
  This is a second paragraph
continued! You create new table cells with a
  line of dashes surrounded by pipes
   
  (Pipes are the vertical lines, “|”)

You can also do fancy things with alignment and footer rows. Here is an example.

1 | Default aligned |Left aligned| Center aligned  | Right aligned  |
2 |-----------------|:-----------|:---------------:|---------------:|
3 | First body part |Second cell | Third cell      | fourth cell    |
4 | Second line     |2nd line    | **strong**      |                |
5 |-----------------|------------|-----------------|----------------|
6 | Second body     |            |                 |                |
7 | 2 line          |            |                 |                |
8 |=================|============|=================|================|
9 | Footer          | footer2    | footer3         | footer4        |
Default aligned Left aligned Center aligned Right aligned
First body part Second cell Third cell fourth cell
Second line 2nd line strong  
Second body      
2 line      
Footer footer2 footer3 footer4

Table Titles

You add a title to a table by adding a title attribute to the table, like this:

{title="Figure 32"}
| City          | Annual Rainfall (inches) |
|------------------------------------------|
| Rome          | 23                       |
| London        | 29                       |

Here’s what that looks like:

 
Figure 32
City Annual Rainfall (inches)
Rome 23
London 29

If you want to set both the title and the width, it looks like this:

{title="Figure 32",width="60%"}
| City          | Annual Rainfall (inches) |
|------------------------------------------|
| Rome          | 23                       |
| London        | 29                       |

HTML Tables

If you try putting an HTML table in a .txt file, you’ll find that it works in the epub and mobi version but is missing in the PDF. Here’s why:

Markdown normally just generates HTML. So it could “support” using HTML tables and any other HTML construct by just not parsing the HTML. But we need to actually parse the Markdown (we use a slightly modified Kramdown parser), in order to generate LaTeX and then PDF.

A note on combining attributes

To combine attributes for a table, add a comma and a space between the attributes, like this:

{title="table title", width="wide"}