| 1 |
Tables |
| 2 |
====== |
| 3 |
|
| 4 |
In contrast to HTML, LaTeX does not support line-breaks in tables with |
| 5 |
"automatic" column widths. Each cell has just one line, paragraphs are |
| 6 |
merged (the writer emits a warning). |
| 7 |
|
| 8 |
.. table:: problems with "auto" widths |
| 9 |
:widths: auto |
| 10 |
|
| 11 |
+-----------+------------------+ |
| 12 |
| 11 | first paragraph | |
| 13 |
| | | |
| 14 |
| | second paragraph | |
| 15 |
+-----------+------------------+ |
| 16 |
| content | 22 | |
| 17 |
| with | | |
| 18 |
| linebreak | | |
| 19 |
+-----------+------------------+ |
| 20 |
|
| 21 |
To provide for arbitrary cell content, the LaTeX writer defaults to |
| 22 |
specifying column widths computed from the source column widths. This |
| 23 |
works sufficiently in many cases: |
| 24 |
|
| 25 |
.. table:: a table with multi-paragraph multi-column cells |
| 26 |
|
| 27 |
+----------+--------------+---------------------------------+-----------+ |
| 28 |
| test | **bold hd** | multicolumn 1 | *emph hd* | |
| 29 |
| | | | | |
| 30 |
| | | With a second paragraph | | |
| 31 |
+----------+--------------+--------------+--------+---------+-----------+ |
| 32 |
| multicolumn 2 | cell | cell | cell | cell | |
| 33 |
| | | | | | |
| 34 |
| With a second paragraph | | | | | |
| 35 |
+----------+--------------+--------------+--------+---------+-----------+ |
| 36 |
| cell | multicolumn 3 (one line, | cell | cell | cell | |
| 37 |
| | but very very very very | | | | |
| 38 |
| | very looooong) | | | | |
| 39 |
+----------+--------------+--------------+--------+---------+-----------+ |
| 40 |
| cell | cell | cell | Short multicolumn 4 | |
| 41 |
+----------+--------------+--------------+------------------------------+ |
| 42 |
|
| 43 |
|
| 44 |
A problem with the source-derived column widths is that simple tables |
| 45 |
often use no padding while grid tables without padding look cramped: |
| 46 |
|
| 47 |
.. table:: simple table, not padded in the source |
| 48 |
|
| 49 |
=== = = = |
| 50 |
A B C D |
| 51 |
=== = = = |
| 52 |
100 2 3 4 |
| 53 |
EUR b c d |
| 54 |
=== = = = |
| 55 |
|
| 56 |
.. table:: grid table, padded cells |
| 57 |
|
| 58 |
+-----+---+---+---+ |
| 59 |
| A | B | C | D | |
| 60 |
+=====+===+===+===+ |
| 61 |
| 100 | 2 | 3 | 4 | |
| 62 |
+-----+---+---+---+ |
| 63 |
| EUR | b | c | d | |
| 64 |
+-----+---+---+---+ |
| 65 |
|
| 66 |
For better typographic results, setting the `width` and/or |
| 67 |
`widths` options of the `table directive`_ is recommended. |
| 68 |
|
| 69 |
.. table:: grid table, auto-width columns |
| 70 |
:widths: auto |
| 71 |
|
| 72 |
+-----+---+---+---+ |
| 73 |
| A | B | C | D | |
| 74 |
+=====+===+===+===+ |
| 75 |
| 100 | 2 | 3 | 4 | |
| 76 |
+-----+---+---+---+ |
| 77 |
| EUR | b | c | d | |
| 78 |
+-----+---+---+---+ |
| 79 |
|
| 80 |
.. table:: table with multi-row header and "auto" column-widths |
| 81 |
:widths: auto |
| 82 |
|
| 83 |
+------------+-------------------+ |
| 84 |
| XXX | Variable Summary | |
| 85 |
| +-------------------+ |
| 86 |
| | Description | |
| 87 |
+============+===================+ |
| 88 |
| multi-column cell | |
| 89 |
+--------------------------------+ |
| 90 |
|
| 91 |
The `width` option overrides "auto" `widths` as standard LaTeX tables |
| 92 |
don't have a global width setting: |
| 93 |
|
| 94 |
.. table:: This table has `widths` "auto" (ignored) and `width` 60%. |
| 95 |
:widths: auto |
| 96 |
:width: 60% |
| 97 |
|
| 98 |
=== = = = |
| 99 |
A B C D |
| 100 |
=== = = = |
| 101 |
100 2 3 4 |
| 102 |
EUR b c d |
| 103 |
=== = = = |
| 104 |
|
| 105 |
.. _table directive: |
| 106 |
https://docutils.sourceforge.io/docs/ref/rst/directives.html#table |
| 107 |
|
| 108 |
|
| 109 |
Nested tables |
| 110 |
------------- |
| 111 |
|
| 112 |
+-----------------------------------------+-----------------+ |
| 113 |
| Lorem ipsum dolor sit amet, consectetur | adipisicing elit| |
| 114 |
+-----------------------------------------+-----------------+ |
| 115 |
| .. table:: | cell 1, 2 | |
| 116 |
| :align: right | | |
| 117 |
| :name: nested table | | |
| 118 |
| | | |
| 119 |
| +-----+-----+ | | |
| 120 |
| | 1 | 2 | | | |
| 121 |
| +-----+-----+ | | |
| 122 |
+-----------------------------------------+-----------------+ |
| 123 |
| table width depends on parent column | same table | |
| 124 |
| | | |
| 125 |
| .. table:: | | |
| 126 |
| :align: center | | |
| 127 |
| | | |
| 128 |
| +-----+-----+ | +-----+-----+ | |
| 129 |
| | 1 | 2 | | | 1 | 2 | | |
| 130 |
| +-----+-----+ | +-----+-----+ | |
| 131 |
| | | |
| 132 |
| better use "auto" widths, see below | in narrow column| |
| 133 |
+-----------------------------------------+-----------------+ |
| 134 |
| .. table:: | cell 3, 2 | |
| 135 |
| :align: right | | |
| 136 |
| :widths: auto | | |
| 137 |
| | | |
| 138 |
| +-----+-----+ | | |
| 139 |
| | 1 | 2 | | | |
| 140 |
| +-----+-----+ | | |
| 141 |
| | | |
| 142 |
| definition: | | |
| 143 |
| list | | |
| 144 |
+-----------------------------------------+-----------------+ |
| 145 |
|
| 146 |
|
| 147 |
TODO |
| 148 |
---- |
| 149 |
|
| 150 |
* Tables with multi-paragraph multi-row cells currently fail due to a |
| 151 |
LaTeX limitation (see https://sourceforge.net/p/docutils/bugs/225/). |
| 152 |
|
| 153 |
* Tweak vertical spacing in table cells containing multiple elements. |
| 154 |
|
| 155 |
See also ``test/functional/input/data/latex-problematic.rst``. |