@@ -1045,114 +1045,77 @@ Use :ref:`reStructuredText tables <rst-tables>`, i.e. either
1045
1045
The :dudir: `table ` directive serves as optional wrapper of the *grid * and
1046
1046
*simple * syntaxes.
1047
1047
1048
- They work fine in HTML output, however there are some gotchas when using tables
1049
- in LaTeX: the column width is hard to determine correctly automatically. For
1050
- this reason, the following directive exists:
1048
+ They work fine in HTML output, but rendering tables to LaTeX is complex.
1051
1049
1052
- .. rst :directive :: .. tabularcolumns:: column spec
1053
-
1054
- This directive gives a "column spec" for the next table occurring in the
1055
- source file. The spec is the second argument to the LaTeX ``tabulary ``
1056
- package's environment (which Sphinx uses to translate tables). It can have
1057
- values like ::
1058
-
1059
- |l|l|l|
1060
-
1061
- which means three left-adjusted, nonbreaking columns. For columns with
1062
- longer text that should automatically be broken, use either the standard
1063
- ``p{width} `` construct, or tabulary's automatic specifiers:
1050
+ .. versionchanged :: 1.6
1051
+ Merged cells (multi-row, multi-column, both) from grid tables containing
1052
+ complex contents such as multiple paragraphs, blockquotes, lists, literal
1053
+ blocks, will render correctly to LaTeX output.
1064
1054
1065
- +-----+------------------------------------------+
1066
- | ``L``| flush left column with automatic width |
1067
- +-----+------------------------------------------+
1068
- | ``R``| flush right column with automatic width |
1069
- +-----+------------------------------------------+
1070
- | ``C``| centered column with automatic width |
1071
- +-----+------------------------------------------+
1072
- | ``J``| justified column with automatic width |
1073
- +-----+------------------------------------------+
1055
+ .. rst :directive :: .. tabularcolumns:: column spec
1074
1056
1075
- The automatic widths of the ``LRCJ `` columns are attributed by ``tabulary ``
1076
- in proportion to the observed shares in a first pass where the table cells
1077
- are rendered at their natural "horizontal" widths.
1057
+ This directive influences only the LaTeX output for the next table in
1058
+ source. The mandatory argument is a column specification (known as an
1059
+ "alignment preamble" in LaTeX idiom). Please refer to a LaTeX
1060
+ documentation, such as the `wiki page `_, for basics of such a column
1061
+ specification.
1078
1062
1079
- By default, Sphinx uses a table layout with `` J `` for every column.
1063
+ .. _ wiki page : https://en.wikibooks.org/wiki/LaTeX/Tables
1080
1064
1081
1065
.. versionadded :: 0.3
1082
1066
1083
- .. versionchanged :: 1.6
1084
- Merged cells may now contain multiple paragraphs and are much better
1085
- handled, thanks to custom Sphinx LaTeX macros. This novel situation
1086
- motivated the switch to ``J `` specifier and not ``L `` by default.
1087
-
1088
- .. hint ::
1067
+ .. note ::
1089
1068
1090
- Sphinx actually uses ``T `` specifier having done ``\newcolumntype{T}{J} ``.
1091
- To revert to previous default, insert ``\newcolumntype{T}{L} `` in the
1092
- LaTeX preamble (see :confval: `latex_elements `).
1069
+ :rst:dir: `tabularcolumns ` conflicts with ``:widths: `` option of table
1070
+ directives. If both are specified, ``:widths: `` option will be ignored.
1093
1071
1094
- A frequent issue with tabulary is that columns with little contents are
1095
- "squeezed". The minimal column width is a tabulary parameter called
1096
- ``\tymin ``. You may set it globally in the LaTeX preamble via
1097
- ``\setlength{\tymin}{40pt} `` for example.
1072
+ Sphinx will render tables with more than 30 rows with ``longtable ``.
1073
+ Besides the ``l ``, ``r ``, ``c `` and ``p{width} `` column specifiers, one can
1074
+ also use ``\X{a}{b} `` (new in version 1.5) which configures the column
1075
+ width to be a fraction ``a/b `` of the total line width and ``\Y{f} `` (new
1076
+ in version 1.6) where ``f `` is a decimal: for example ``\Y{0.2} `` means that
1077
+ the column will occupy ``0.2 `` times the line width.
1098
1078
1099
- Else, use the :rst:dir: `tabularcolumns ` directive with an explicit
1100
- ``p{40pt} `` (for example) for that column. You may use also ``l ``
1101
- specifier but this makes the task of setting column widths more difficult
1102
- if some merged cell intersects that column.
1079
+ When this directive is used for a table with at most 30 rows, Sphinx will
1080
+ render it with ``tabulary ``. One can then use specific column types ``L ``
1081
+ (left), ``R `` (right), ``C `` (centered) and ``J `` (justified). They have
1082
+ the effect of a ``p{width} `` (i.e. each cell is a LaTeX ``\parbox ``) with
1083
+ the specified internal text alignment and an automatically computed
1084
+ ``width ``.
1103
1085
1104
1086
.. warning ::
1105
1087
1106
- Tables with more than 30 rows are rendered using ``longtable ``, not
1107
- ``tabulary ``, in order to allow pagebreaks. The ``L ``, ``R ``, ...
1108
- specifiers do not work for these tables.
1109
-
1110
- Tables that contain list-like elements such as object descriptions,
1111
- blockquotes or any kind of lists cannot be set out of the box with
1112
- ``tabulary ``. They are therefore set with the standard LaTeX ``tabular ``
1113
- (or ``longtable ``) environment if you don't give a ``tabularcolumns ``
1114
- directive. If you do, the table will be set with ``tabulary `` but you
1115
- must use the ``p{width} `` construct (or Sphinx's ``\X `` and ``\Y ``
1116
- specifiers described below) for the columns containing these elements.
1117
-
1118
- Literal blocks do not work with ``tabulary `` at all, so tables containing
1119
- a literal block are always set with ``tabular ``. The verbatim environment
1120
- used for literal blocks only works in ``p{width} `` (and ``\X `` or ``\Y ``)
1121
- columns, hence Sphinx generates such column specs for tables containing
1122
- literal blocks.
1123
-
1124
- Since Sphinx 1.5, the ``\X{a}{b} `` specifier is used (there *is * a backslash
1125
- in the specifier letter). It is like ``p{width} `` with the width set to a
1126
- fraction ``a/b `` of the current line width. You can use it in the
1127
- :rst:dir: `tabularcolumns ` (it is not a problem if some LaTeX macro is also
1128
- called ``\X ``.)
1129
-
1130
- It is *not * needed for ``b `` to be the total number of columns, nor for the
1131
- sum of the fractions of the ``\X `` specifiers to add up to one. For example
1132
- ``|\X{2}{5}|\X{1}{5}|\X{1}{5}| `` is legitimate and the table will occupy
1133
- 80% of the line width, the first of its three columns having the same width
1134
- as the sum of the next two.
1135
-
1136
- This is used by the ``:widths: `` option of the :dudir: `table ` directive.
1137
-
1138
- Since Sphinx 1.6, there is also the ``\Y{f} `` specifier which admits a
1139
- decimal argument, such has ``\Y{0.15} ``: this would have the same effect as
1140
- ``\X{3}{20} ``.
1088
+ - Cells that contain list-like elements such as object descriptions,
1089
+ blockquotes or any kind of lists are not compatible with the ``LRCJ ``
1090
+ column types. The column type must then be some ``p{width} `` with an
1091
+ explicit ``width `` (or ``\X{a}{b} `` or ``\Y{f} ``).
1141
1092
1142
- .. versionchanged :: 1.6
1093
+ - Literal blocks do not work with ``tabulary `` at all. Sphinx will
1094
+ fall back to ``tabular `` or ``longtable `` environments and generate a
1095
+ suitable column specification.
1143
1096
1144
- Merged cells from complex grid tables (either multi-row, multi-column, or
1145
- both) now allow blockquotes, lists, literal blocks, ... as do regular
1146
- cells .
1097
+ In absence of the :rst:dir: ` tabularcolumns ` directive, and for a table with at
1098
+ most 30 rows and no problematic cells as described in the above warning,
1099
+ Sphinx uses `` tabulary `` and the `` J `` column-type for every column .
1147
1100
1148
- Sphinx's merged cells interact well with ``p{width} ``, ``\X{a}{b} ``,
1149
- ``\Y{f} `` and tabulary's columns.
1101
+ .. versionchanged :: 1.6
1150
1102
1151
- .. note ::
1103
+ Formerly, the ``L `` column-type was used (text is flushed-left). To revert
1104
+ to this, include ``\newcolumntype{T}{L} `` in the LaTeX preamble, as in fact
1105
+ Sphinx uses ``T `` and sets it by default to be an alias of ``J ``.
1152
1106
1153
- :rst:dir: `tabularcolumns ` conflicts with ``:widths: `` option of table
1154
- directives. If both are specified, ``:widths: `` option will be ignored.
1107
+ .. hint ::
1108
+
1109
+ A frequent issue with ``tabulary `` is that columns with little contents
1110
+ appear to be "squeezed". One can add to the LaTeX preamble for example
1111
+ ``\setlength{\tymin}{40pt} `` to ensure a minimal column width of ``40pt ``,
1112
+ the ``tabulary `` default of ``10pt `` being too small.
1113
+
1114
+ .. hint ::
1155
1115
1116
+ To force usage of the LaTeX ``longtable `` environment pass ``longtable `` as
1117
+ a ``:class: `` option to :dudir: `table `, :dudir: `csv-table `, or
1118
+ :dudir: `list-table `. Use :ref: `rst-class <rstclass >` for other tables.
1156
1119
1157
1120
Math
1158
1121
----
0 commit comments