|
From: <mi...@us...> - 2021-09-30 10:15:48
|
Revision: 8835
http://sourceforge.net/p/docutils/code/8835
Author: milde
Date: 2021-09-30 10:15:45 +0000 (Thu, 30 Sep 2021)
Log Message:
-----------
LaTeX writer: New algorithm for table colum widths. Fixes bug #422.
New configuration setting "legacy_column_widths" for backwards
compatibility.
Only write "continued on next page..." if it fits without
making the table columns wider.
Table `width` option overrides conflicting "auto" column `widths`.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docs/ref/doctree.txt
trunk/docutils/docs/ref/rst/directives.txt
trunk/docutils/docs/user/config.txt
trunk/docutils/docs/user/latex.txt
trunk/docutils/docutils/parsers/rst/directives/tables.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/functional/expected/latex_cornercases.tex
trunk/docutils/test/functional/expected/latex_memoir.tex
trunk/docutils/test/functional/expected/standalone_rst_latex.tex
trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
trunk/docutils/test/functional/input/data/tables_latex.txt
trunk/docutils/test/functional/tests/latex_cornercases.py
trunk/docutils/test/test_writers/test_latex2e.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/HISTORY.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -111,7 +111,6 @@
- Overwrite methods in _html_base.HTMLTranslator that use HTM5 tags
(details, aside, nav, ...) and attributes (role, aria-level).
-
* docutils/writers/latex2e/__init__.py
- The setting `legacy_class_functions`_ now defaults to "False".
@@ -129,6 +128,19 @@
- Improve spacing and allow customization of Docutils-generated table
of contents.
+ - New algorithm for table colum widths. Fixes bug #422.
+ New configuration setting legacy_column_widths_.
+
+ Table.set_table_style() arguments changed.
+
+ Only write "continued on next page..." if it fits
+ without making the table columns wider.
+
+ Table `width` option overrides conflicting "auto" column `widths`.
+
+.. _legacy_column_widths: docs/user/config.html#legacy-column-widths
+
+
* docutils/writers/latex2e/docutils.sty
- Fix excessive padding above sidebar titles.
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/RELEASE-NOTES.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -31,11 +31,12 @@
deprecated ``<colgroup><col width="...">...``.
The `html5` writer will default to ``:widths: auto`` and use
- ``style="width: ..%"`` if the `"widths" option`__ sets explicite table
- column widths. Use ``:widths: grid`` to keep the current default
- column widths.
+ ``style="width: ..%"`` if the `"widths" option`__ is used.
+ Use the table-style__ setting with value "colwidths-grid" to
+ keep the current default.
- __ docs/ref/rst/directives.html#table
+ __ docs/ref/rst/directives.html#table
+ __ docs/user/config.html#table-style
- Move attribution behind the blockquote to comply with the
`"living standard"`__?
@@ -48,11 +49,13 @@
* `latex2e` writer:
- - Change default of ``use_latex_citations`` to True.
+ - Change default of use_latex_citations_ setting to True.
- - Remove ``--use-verbatim-when-possible`` option
- (use ``--literal-block-env=verbatim``).
+ - Change default of legacy_column_widths_ setting to False.
+ - Remove ``use_verbatim_when_possible`` setting
+ (use literal_block_env_: verbatim).
+
* Remove the "rawsource" attribute and argument from nodes.Text:
we store the null-escaped text in Text nodes since 0.16 so there is no
additional information in the rawsource.
@@ -78,6 +81,8 @@
.. _rst2html.py: docs/user/tools.html#rst2html-py
.. _reference name: docs/ref/rst/restructuredtext.html#reference-names
.. _html_writer: docs/user/config.html#html-writer
+.. _literal_block_env: docs/user/config.html#literal-block-env
+.. _use_latex_citations: docs/user/config.html#use-latex-citations
Release 0.18.dev
@@ -146,9 +151,11 @@
* docutils/utils/math/math2html.py,
docutils/utils/math/latex2mathml.py
- Major refactoring and fixes/additions
- (cf. `LaTeX syntax for mathematics`_).
+ - Major refactoring and fixes/additions
+ (cf. `LaTeX syntax for mathematics`_).
+* New configuration setting: [latex writers] legacy_column_widths_.
+
* Various bugfixes and improvements (see HISTORY_).
__ docs/ref/doctree.html#meta
@@ -157,8 +164,9 @@
.. _id_prefix: docs/user/config.html#id-prefix
.. _auto_id_prefix: docs/user/config.html#auto-id-prefix
.. _details disclosure elements:
- https://www.w3.org/TR/html52/interactive-elements.html#the-details-element
+ https://www.w3.org/TR/html52/interactive-elements.html#the-details-element
.. _LaTeX syntax for mathematics: docs/ref/rst/mathematics.html
+.. _legacy_column_widths: docs/user/config.html#legacy-column-widths
Release 0.17.1 (2021-04-16)
Modified: trunk/docutils/docs/ref/doctree.txt
===================================================================
--- trunk/docutils/docs/ref/doctree.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/docs/ref/doctree.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -978,6 +978,9 @@
In contrast to the definition in the exchange-table-model_,
unitless values of the "colwidth" are interpreted as proportional
values, not fixed values with unit "pt".
+
+ .. The reference implementation `html4css2` converts column
+ widths values to percentages.
Future versions of Docutils may use the standard form
``number*``, e.g., “5*” for 5 times the proportion.
Modified: trunk/docutils/docs/ref/rst/directives.txt
===================================================================
--- trunk/docutils/docs/ref/rst/directives.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/docs/ref/rst/directives.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -947,18 +947,11 @@
The following options are recognized:
-``widths`` : integer [integer...] or "auto"
- A list of relative column widths.
- The default is equal-width columns (100%/#columns).
- "auto" delegates the determination of column widths to the backend
- (LaTeX, the HTML browser, ...).
-
-``width`` : `length`_ or `percentage`_
- Sets the width of the table to the specified length or percentage
- of the line width. If omitted, the renderer determines the width
- of the table based on its contents or the column ``widths``.
-
+``align`` : "left", "center", or "right"
+ The horizontal alignment of the table.
+ (New in Docutils 0.13)
+
``header-rows`` : integer
The number of rows of list data to use in the table header.
Defaults to 0.
@@ -967,10 +960,22 @@
The number of table columns to use as stubs (row titles, on the
left). Defaults to 0.
-``align`` : "left", "center", or "right"
- The horizontal alignment of the table.
- (New in Docutils 0.13)
+ .. _table width:
+``width`` : `length`_ or `percentage`_
+ Sets the width of the table to the specified length or percentage
+ of the line width. If omitted, the renderer determines the width
+ of the table based on its contents or the column ``widths``.
+
+ .. _column widths:
+
+``widths`` : integer [integer...] or "auto"
+ A list of relative column widths.
+ The default is equal-width columns (100%/#columns).
+
+ "auto" delegates the determination of column widths to the backend
+ (LaTeX, the HTML browser, ...).
+
and the common options class_ and name_.
Modified: trunk/docutils/docs/user/config.txt
===================================================================
--- trunk/docutils/docs/user/config.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/docs/user/config.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -1221,6 +1221,13 @@
(leave out the ``<colgroup>`` column specification).
Overridden by the "widths" option of the `table directive`_.
+.. TODO: the HTML5 writer also supports
+
+ colwidths-grid
+ Backwards compatibility setting. Write column widths
+ determined from the source to the HTML file.
+ Overridden by the "widths" option of the `table directive`_.
+
Default: "". Option: ``--table-style``.
.. _table directive: ../ref/rst/directives.html#table
@@ -1588,6 +1595,7 @@
.. _hyperref TeX package: http://tug.org/applications/hyperref/
+
latex_preamble
~~~~~~~~~~~~~~
@@ -1607,7 +1615,7 @@
values are handled with wrappers and admonitions use the ``DUadmonition``
environment. See `Generating LaTeX with Docutils`__ for details.
-Default: False.
+Default: False (changed in Docutils 0.18).
Options: ``--legacy-class-functions``, ``--new-class-functions``.
New in Docutils 0.17.
@@ -1614,6 +1622,26 @@
__ latex.html#classes
+
+legacy_column_widths
+~~~~~~~~~~~~~~~~~~~~
+
+Use "legacy algorithm" or new algorithm to determine table column widths.
+
+The new algorithm limits the table width to the text width or specified
+table width and keeps the ratio of specified column widths.
+
+Custom table and/or column widths can be set with the respective options
+of the `table directive`_. See also `Generating LaTeX with Docutils`__.
+
+Default: True (will change to False in 0.19).
+Options: ``--legacy-column-widths``, ``--new-column-widths``.
+
+New in Docutils 0.18.
+
+__ latex.html#table-style
+
+
literal_block_env
~~~~~~~~~~~~~~~~~
@@ -1628,6 +1656,7 @@
.. _parsed literal: ../ref/rst/directives.html#parsed-literal
+
reference_label
~~~~~~~~~~~~~~~
@@ -1744,34 +1773,14 @@
Specify the default style for tables_.
See also `table_style [html writers]`_.
-Supported values:
+Supported values: "booktabs", "borderless", "colwidths-auto", and "standard".
+See `Generating LaTeX with Docutils`__ for details.
-standard
- Borders around all cells.
+Default: "standard". Option: ``--table-style``.
-booktabs
- A line above and below the table and one after the head.
+__ latex.html#tables
-borderless
- No borders.
-align-left, align-center, align-right
- Align tables.
-
-colwidths-auto, colwidths-given
- Column width determination by LaTeX or Docutils (default).
- Overridden by the `table directive`_'s :widths: option.
-
- .. warning::
-
- ``colwidths-auto`` is only suited for tables with simple cell content.
-
- LaTeX puts the content of auto-sized columns on one line (merging
- paragraphs) and may fail with complex content.
-
-Default: "standard". Option: ``--table-style``.
-
-
.. _template [latex writers]:
template
Modified: trunk/docutils/docs/user/latex.txt
===================================================================
--- trunk/docutils/docs/user/latex.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/docs/user/latex.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -250,7 +250,7 @@
``language-`` set the elements language property.
* The table element recognizes some special class values. See section
- table_.
+ `table style`_.
* If the legacy-class-functions_ setting is True, the special macros
``\DUadmonition`` and ``\DUtitle`` are written with a comma separated
@@ -1614,64 +1614,54 @@
.. _CSS length unit ``px``: http://www.w3.org/TR/css-values-3/#px
.. _reference pixel: http://www.w3.org/TR/css-values-3/#reference-pixel
-table
------
+table style
+------------
-A pre-configured table style can be globally selected via the table-style_
+A pre-configured *table style* can be globally selected via the table_style_
setting or set for individual tables via a `class directive`_ or the class
option of the `table directive`_.
-.. _table-style: config.html#table-style-latex-writers
-.. _table directive: ../ref/rst/directives.html#table
+Supported values:
-topic element
--------------
+standard
+ Borders around all cells.
-A topic_ is like a block quote with a title, or a self-contained section
-with no subsections. Topics and rubrics can be used at places where a
-`section title`_ is not allowed (e.g. inside a directive).
+booktabs
+ A line above and below the table and one after the head.
-Example:
- Use a standard paragraph for a topic::
+borderless
+ No borders.
- \newcommand{\DUCLASStopic}{%
- \renewenvironment{quote}{}{}%
- }
+colwidths-auto
+ Column width determination by LaTeX.
+ Overridden by the `table directive`_'s "widths" option.
-.. _topic: ../ref/rst/directives.html#topic
-.. _section title: ../ref/rst/restructuredtext.html#sections
+ .. warning::
+ ``colwidths-auto`` is only suited for tables with simple cell content.
-titles
-------
+ LaTeX puts the content of auto-sized columns on one line (merging
+ paragraphs) and may fail with complex content.
-The titles of admonitions_, sidebar_, and `topic element`_ use
-the ``\DUtitle`` command.
+.. eventually in future
-Example 1:
- a centered and somewhat larger title for topcis::
+ align-left, align-center, align-right
+ Align tables.
- \newcommand*{\DUCLASStopic}{
- \renewcommand*{\DUtitle}[1]{\subsection*{\centering #1}
- }
+By default, *column widths* are computed from the source column widths.
+The `legacy_column_widths`_ setting selects the conversion algorithm.
+Custom column widths can be set with the "widths" option of the `table
+directive`_.
-Example 2:
- a right-pointing hand as title for the "attention" directive::
+See also the section on problems with tables_ below.
- \usepackage{pifont}
- \newcommand*{\DUCLASSattention}{
- \renewcommand*{\DUtitle}[1]{\ding{43}}
- }
+.. _new_column_widths:
+.. _legacy_column_widths: config.html#legacy-column-widths
+.. _table_style: config.html#table-style-latex-writers
+.. _"widths" option:
+.. _table directive: ../ref/rst/directives.html#table
- The title argument is "swallowed" by the command.
- To have both, hand and title use::
- \usepackage{pifont}
- \newcommand*{\DUCLASSattention}{
- \newcommand*{\DUtitle}[1]{\ding{43} #1}
- }
-
-
table of contents
-----------------
@@ -1734,6 +1724,36 @@
.. _interpreted text: ../ref/rst/restructuredtext.html#interpreted-text
+titles
+------
+
+The titles of admonitions_, sidebar_, and `topic element`_ use
+the ``\DUtitle`` command.
+
+Example 1:
+ a centered and somewhat larger title for topcis::
+
+ \newcommand*{\DUCLASStopic}{
+ \renewcommand*{\DUtitle}[1]{\subsection*{\centering #1}
+ }
+
+Example 2:
+ a right-pointing hand as title for the "attention" directive::
+
+ \usepackage{pifont}
+ \newcommand*{\DUCLASSattention}{
+ \renewcommand*{\DUtitle}[1]{\ding{43}}
+ }
+
+ The title argument is "swallowed" by the command.
+ To have both, hand and title use::
+
+ \usepackage{pifont}
+ \newcommand*{\DUCLASSattention}{
+ \newcommand*{\DUtitle}[1]{\ding{43} #1}
+ }
+
+
text encoding
-------------
@@ -1778,6 +1798,24 @@
.. _ucs: http://ctan.org/pkg/unicode
+topic element
+-------------
+
+A topic_ is like a block quote with a title, or a self-contained section
+with no subsections. Topics and rubrics can be used at places where a
+`section title`_ is not allowed (e.g. inside a directive).
+
+Example:
+ Use a standard paragraph for a topic::
+
+ \newcommand{\DUCLASStopic}{%
+ \renewenvironment{quote}{}{}%
+ }
+
+.. _topic: ../ref/rst/directives.html#topic
+.. _section title: ../ref/rst/restructuredtext.html#sections
+
+
transition element
------------------
@@ -1849,7 +1887,7 @@
maybe far away from the footnote mark (see e.g. `<rst/demo.txt>`_).
To get footnote mark and text at the same page, keep footnote mark and
-footnote text close together!
+footnote text close together.
non-breaking hyperlinks
@@ -1908,7 +1946,8 @@
Images__ are included in LaTeX with the help of the `graphicx` package. The
supported file formats depend on the used driver:
-* pdflatex_ and xelatex_ work with PNG, JPG, or PDF, but **not EPS**.
+* pdflatex_, lualatex, and xelatex_ work with PNG, JPG, or PDF,
+ but **not EPS**.
* Standard latex_ can include **only EPS** graphics, no other format.
* latex + dvipdfmx works with EPS and JPG (add 'dvipdfmx' to the
documentoptions_ or graphicx-option_ setting
@@ -2045,8 +2084,7 @@
page foot.
Workaround:
- Select footnote and citation handling with the docutils-footnotes_ and
- use-latex-citations_ options.
+ Select citation handling with the use_latex_citations_ option.
If ``use-latex-citations`` is used, a bibliography is inserted right at
the end of the document. *This should be customizable*.
@@ -2056,36 +2094,22 @@
group, i.e. ``[cite1]_ [cite2]_`` results in ``\cite{cite1,cite2}``.
The appearance in the output can be configured in a `style sheet`_.
-.. _docutils-footnotes: config.html#docutils-footnotes
-.. _use-latex-citations: config.html#use-latex-citations
+.. _use_latex_citations: config.html#use-latex-citations
Tables
``````
-* reST-documents line length is assumed to be 80 characters. The
- *tablewidth* is set relative to this value. If someone produces documents
- with line length of 132 this will lead to suboptimal results.
+* Too wide tables (cf. `bug #422`_):
- You may use the `:widths:` option to manually set the table column widths.
+ Try the new_column_widths_ algorithm or use the `"widths" option`_ to
+ manually set the table column widths.
-* Table: multicol cells are always left aligned.
-
* Table cells with both multirow and multicolumn are currently not possible.
-* literal-blocks in table cells:
+.. _bug #422: https://sourceforge.net/p/docutils/bugs/422/
- - If verbatim or flushleft is used one gets vertical space above and below.
- - This is bad for the topmost paragraph in a cell, therefore the writer
- uses raggedright.
- - Ragged right fails on followup paragraphs as the vertical space would be
- missing.
-* ``--table-style=booktabs``, ``..class:: booktab``: `booktabs` version
- 1.00 does not work with `longtable`. This is solved in newer versions
- (current is 2005/04/14 v1.61803).
-
-
Figures
```````
Modified: trunk/docutils/docutils/parsers/rst/directives/tables.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/tables.py 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/docutils/parsers/rst/directives/tables.py 2021-09-30 10:15:45 UTC (rev 8835)
@@ -164,7 +164,7 @@
colspec['colwidth'] = col_width
if self.widths == 'auto':
table_node['classes'] += ['colwidths-auto']
- elif self.widths: # override "table-style" setting
+ elif self.widths: # "grid" or list of integers
table_node['classes'] += ['colwidths-given']
self.add_name(table_node)
if title:
@@ -485,7 +485,7 @@
table = nodes.table()
if self.widths == 'auto':
table['classes'] += ['colwidths-auto']
- elif self.widths: # override "table-style" setting
+ elif self.widths: # explicitely set column widths
table['classes'] += ['colwidths-given']
tgroup = nodes.tgroup(cols=len(col_widths))
table += tgroup
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2021-09-30 10:15:45 UTC (rev 8835)
@@ -52,8 +52,10 @@
r'\usepackage{mathptmx} % Times',
r'\usepackage[scaled=.90]{helvet}',
r'\usepackage{courier}'])
- table_style_values = ('standard', 'booktabs', 'nolines', 'borderless',
- 'colwidths-auto', 'colwidths-given')
+ table_style_values = (# TODO: align-left, align-center, align-right,
+ 'booktabs', 'borderless', 'colwidths-auto',
+ 'colwidths-given', # set by parser if "widths" option is specified
+ 'nolines', 'standard')
settings_spec = (
'LaTeX-Specific Options',
@@ -226,6 +228,17 @@
{'dest': 'legacy_class_functions',
'action': 'store_false',
'validator': frontend.validate_boolean}),
+ ('Use legacy algorithm to determine table column widths (default).',
+ ['--legacy-column-widths'],
+ {'default': True,
+ 'action': 'store_true',
+ 'validator': frontend.validate_boolean}),
+ ('Use new algorithm to determine table column widths '
+ '(future default).',
+ ['--new-column-widths'],
+ {'dest': 'legacy_column_widths',
+ 'action': 'store_false',
+ 'validator': frontend.validate_boolean}),
# TODO: implement "latex footnotes" alternative
('Footnotes with numbers/symbols by Docutils. (default) '
'(The alternative, --latex-footnotes, is not implemented yet.)',
@@ -498,7 +511,7 @@
class PreambleCmds(object):
"""Building blocks for the latex preamble."""
-# Requirements
+# Requirements and Setup
PreambleCmds.color = r"""\usepackage{color}"""
@@ -518,11 +531,9 @@
PreambleCmds.table = r"""\usepackage{longtable,ltcaption,array}
\setlength{\extrarowheight}{2pt}
\newlength{\DUtablewidth} % internal use in tables"""
-# if booktabs:
-# \newcommand{\DUcolumnwidth}[1]{\dimexpr #1\DUtablewidth-2\tabcolsep\relax}
-# else:
-# \newcommand{\DUcolumnwidth}[1]{\dimexpr #1\DUtablewidth-2\tabcolsep-\arrayrulewidth\relax}
+PreambleCmds.table_columnwidth = r"""\newcommand{\DUcolumnwidth}[1]{\dimexpr#1\DUtablewidth-2\tabcolsep\relax}"""
+
PreambleCmds.textcomp = r"""\usepackage{textcomp} % text symbol macros"""
# TODO? Options [force,almostfull] prevent spurious error messages,
# see de.comp.text.tex/2005-12/msg01855
@@ -827,9 +838,6 @@
class Table(object):
"""Manage a table while traversing.
- Maybe change to a mixin defining the visit/departs, but then
- class Table internal variables are in the Translator.
-
Table style might be
:standard: horizontal and vertical lines
@@ -838,11 +846,11 @@
:nolines: alias for borderless
:colwidths-auto: column widths determined by LaTeX
- :colwidths-given: use colum widths from rST source
"""
def __init__(self, translator, latex_type):
self._translator = translator
self._latex_type = latex_type
+ self.legacy_column_widths = False
self.close()
self._colwidths = []
@@ -867,15 +875,20 @@
def is_open(self):
return self._open
- def set_table_style(self, table_style, classes):
+ def set_table_style(self, node, settings):
+ self.legacy_column_widths = settings.legacy_column_widths
+ if 'align' in node:
+ self.set('align', node['align'])
+ # TODO: elif 'align' in classes/settings.table-style:
+ # self.set('align', ...)
borders = [cls.replace('nolines', 'borderless')
- for cls in ['standard'] + table_style + classes
- if cls in ('standard', 'booktabs', 'borderless', 'nolines')]
+ for cls in ['standard'] + settings.table_style + node['classes']
+ if cls in ('standard', 'booktabs', 'borderless', 'nolines')]
self.borders = borders[-1]
- self.colwidths_auto = (('colwidths-auto' in classes
- and 'colwidths-given' not in table_style)
- or ('colwidths-auto' in table_style
- and ('colwidths-given' not in classes)))
+ self.colwidths_auto = (('colwidths-auto' in node['classes']
+ or 'colwidths-auto' in settings.table_style)
+ and 'colwidths-given' not in node['classes']
+ and 'width' not in node)
def get_latex_type(self):
if self._latex_type == 'longtable' and not self.caption:
@@ -911,7 +924,12 @@
else:
opening = [r'\begin{%s}%s' % (latex_type, align)]
if not self.colwidths_auto:
- opening.insert(-1, r'\setlength{\DUtablewidth}{%s}%%'%width)
+ if self.borders == 'standard' and not self.legacy_column_widths:
+ opening.insert(-1, r'\setlength{\DUtablewidth}'
+ r'{\dimexpr%s-%i\arrayrulewidth\relax}%%'
+ % (width, len(self._col_specs)+1))
+ else:
+ opening.insert(-1, r'\setlength{\DUtablewidth}{%s}%%' % width)
return '\n'.join(opening)
def get_closing(self):
@@ -932,39 +950,55 @@
def get_colspecs(self, node):
"""Return column specification for longtable.
-
- Assumes reST line length being 80 characters.
- Table width is hairy.
-
- === ===
- ABC DEF
- === ===
-
- usually gets too narrow, therefore we add 1 (fiddlefactor).
"""
bar = self.get_vertical_bar()
- self._rowspan= [0] * len(self._col_specs)
+ self._rowspan = [0] * len(self._col_specs)
if self.colwidths_auto:
self._colwidths = []
latex_colspecs = ['l'] * len(self._col_specs)
- else:
+ elif self.legacy_column_widths:
+ # use old algorithm for backwards compatibility
width = 80 # assumed standard line length
+ factor = 0.93 # do not make it full linewidth
# first see if we get too wide.
total_width = sum(node['colwidth']+1 for node in self._col_specs)
- # do not make it full linewidth
- factor = 0.93
- if total_width > 80:
+ if total_width > width:
factor *= width / total_width
- self._colwidths = [(factor * float(node['colwidth']+1)/width)
+ self._colwidths = [(factor * (node['colwidth']+1)/width)
+ 0.005 for node in self._col_specs]
latex_colspecs = ['p{%.3f\\DUtablewidth}' % colwidth
for colwidth in self._colwidths]
+ else:
+ # No of characters corresponding to table width = 100%
+ # Characters/line with LaTeX article, A4, Times, default margins
+ # depends on character: M: 40, A: 50, x: 70, i: 120.
+ norm_length = 40
+ # Allowance to prevent unpadded columns like
+ # === ==
+ # ABC DE
+ # === ==
+ # getting too narrow:
+ if 'colwidths-given' not in node.parent.parent['classes']:
+ allowance = 1
+ else:
+ allowance = 0 # "widths" option specified, use exact ratio
+ self._colwidths = [(node['colwidth']+allowance)/norm_length
+ for node in self._col_specs]
+ total_width = sum(self._colwidths)
+ # Limit to 100%, force 100% if table width is specified:
+ if total_width > 1 or 'width' in node.parent.parent.attributes:
+ self._colwidths = [colwidth/total_width
+ for colwidth in self._colwidths]
+ latex_colspecs = ['p{\\DUcolumnwidth{%.3f}}' % colwidth
+ for colwidth in self._colwidths]
return bar + bar.join(latex_colspecs) + bar
def get_column_width(self):
"""Return columnwidth for current cell (not multicell)."""
try:
- return '%.2f\\DUtablewidth' % self._colwidths[self._cell_in_row]
+ if self.legacy_column_widths:
+ return '%.2f\\DUtablewidth' % self._colwidths[self._cell_in_row]
+ return '\\DUcolumnwidth{%.2f}' % self._colwidths[self._cell_in_row]
except IndexError:
return '*'
@@ -971,10 +1005,12 @@
def get_multicolumn_width(self, start, len_):
"""Return sum of columnwidths for multicell."""
try:
- mc_width = sum([width
- for width in ([self._colwidths[start + co]
- for co in range(len_)])])
- return 'p{%.2f\\DUtablewidth}' % mc_width
+ multicol_width = sum([width
+ for width in ([self._colwidths[start + co]
+ for co in range(len_)])])
+ if self.legacy_column_widths:
+ return 'p{%.2f\\DUtablewidth}' % multicol_width
+ return 'p{\\DUcolumnwidth{%.3f}}' % multicol_width
except IndexError:
return 'l'
@@ -1009,11 +1045,17 @@
if 1 == self._translator.thead_depth():
a.append('\\endfirsthead\n')
else:
+ n_c = len(self._col_specs)
a.append('\\endhead\n')
- a.append(r'\multicolumn{%d}{r}' % len(self._col_specs) +
- r'{... continued on next page} \\')
- a.append('\n\\endfoot\n\\endlastfoot\n')
- # for longtable one could add firsthead, foot and lastfoot
+ # footer on all but last page (if it fits):
+ twidth = sum([node['colwidth']+2 for node in self._col_specs])
+ if twidth > 30 or (twidth > 12 and not self.colwidths_auto):
+ a.append(r'\multicolumn{%d}{%s}'
+ % (n_c, self.get_multicolumn_width(0, n_c))
+ + r'{\raggedleft\ldots continued on next page}\\'
+ + '\n')
+ a.append('\\endfoot\n\\endlastfoot\n')
+ # for longtable one could add firsthead, foot and lastfoot
self._in_thead -= 1
return a
@@ -2906,6 +2948,8 @@
def visit_table(self, node):
self.duclass_open(node)
self.requirements['table'] = PreambleCmds.table
+ if not self.settings.legacy_column_widths:
+ self.requirements['table1'] = PreambleCmds.table_columnwidth
if self.active_table.is_open():
self.table_stack.append(self.active_table)
# nesting longtable does not work (e.g. 2007-04-18)
@@ -2918,10 +2962,7 @@
self.d_class.section(self.section_level).find('paragraph') != -1):
self.out.append('\\leavevmode')
self.active_table.open()
- self.active_table.set_table_style(self.settings.table_style,
- node['classes'])
- if 'align' in node:
- self.active_table.set('align', node['align'])
+ self.active_table.set_table_style(node, self.settings)
if self.active_table.borders == 'booktabs':
self.requirements['booktabs'] = r'\usepackage{booktabs}'
self.push_output_collector([])
Modified: trunk/docutils/test/functional/expected/latex_cornercases.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_cornercases.tex 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/functional/expected/latex_cornercases.tex 2021-09-30 10:15:45 UTC (rev 8835)
@@ -18,6 +18,7 @@
\usepackage{longtable,ltcaption,array}
\setlength{\extrarowheight}{2pt}
\newlength{\DUtablewidth} % internal use in tables
+\newcommand{\DUcolumnwidth}[1]{\dimexpr#1\DUtablewidth-2\tabcolsep\relax}
\usepackage{textcomp} % text symbol macros
%%% Custom LaTeX preamble
@@ -61,20 +62,6 @@
}
\fi
-% numerical or symbol footnotes with hyperlinks and backlinks
-\providecommand*{\DUfootnotemark}[3]{%
- \raisebox{1em}{\hypertarget{#1}{}}%
- \hyperlink{#2}{\textsuperscript{#3}}%
-}
-\providecommand{\DUfootnotetext}[4]{%
- \begingroup%
- \renewcommand{\thefootnote}{%
- \protect\raisebox{1em}{\protect\hypertarget{#1}{}}%
- \protect\hyperlink{#2}{#3}}%
- \footnotetext{#4}%
- \endgroup%
-}
-
% legend environment (in figures and formal tables)
\ifthenelse{\isundefined{\DUlegend}}{
\newenvironment{DUlegend}{\small}{}
@@ -334,8 +321,6 @@
In contrast to HTML, LaTeX does not support line-breaks in tables with
\textquotedbl{}automatic\textquotedbl{} column widths. Each cell has just one line, paragraphs are
merged (the writer emits a warning).
-To provide for arbitrary cell content, the LaTeX writer defaults to
-specifying column widths computed from the source:
\begin{longtable}{|l|l|}
\caption{problems with \textquotedbl{}auto\textquotedbl{} widths}\\
@@ -349,22 +334,19 @@
\hline
\end{longtable}
-Docutils stores table column widths in the \textquotedbl{}doctree\textquotedbl{} (in characters,
-excluding the separator). In the .tex source, column widths are written
-as percent of the \texttt{\textbackslash{}linewidth}, computed on the assumption that an
-average text line is 80 characters wide. An allowance added to the stored
-column widths compensates the padding (\texttt{\textbackslash{}tabcolsep}) added by LaTeX.
-The algorightm provides a working solution in many cases.\DUfootnotemark{footnote-reference-1}{footnote-1}{1}
+To provide for arbitrary cell content, the LaTeX writer defaults to
+specifying column widths computed from the source column widths. This
+works sufficiently in many cases:
-\setlength{\DUtablewidth}{\linewidth}%
-\begin{longtable}{|p{0.133\DUtablewidth}|p{0.179\DUtablewidth}|p{0.179\DUtablewidth}|p{0.110\DUtablewidth}|p{0.121\DUtablewidth}|p{0.145\DUtablewidth}|}
-\caption{a table with multi-paragraph multicolumn cells}\\
+\setlength{\DUtablewidth}{\dimexpr\linewidth-7\arrayrulewidth\relax}%
+\begin{longtable}{|p{\DUcolumnwidth{0.153}}|p{\DUcolumnwidth{0.208}}|p{\DUcolumnwidth{0.208}}|p{\DUcolumnwidth{0.125}}|p{\DUcolumnwidth{0.139}}|p{\DUcolumnwidth{0.167}}|}
+\caption{a table with multi-paragraph multi-column cells}\\
\hline
test
&
\textbf{bold hd}
- & \multicolumn{3}{p{0.41\DUtablewidth}|}{%
+ & \multicolumn{3}{p{\DUcolumnwidth{0.472}}|}{%
multicolumn 1
With a second paragraph
@@ -372,7 +354,7 @@
\emph{emph hd}
\\
\hline
-\multicolumn{2}{|p{0.31\DUtablewidth}|}{%
+\multicolumn{2}{|p{\DUcolumnwidth{0.361}}|}{%
multicolumn 2
With a second paragraph
@@ -388,7 +370,7 @@
\hline
cell
- & \multicolumn{2}{p{0.36\DUtablewidth}|}{%
+ & \multicolumn{2}{p{\DUcolumnwidth{0.417}}|}{%
multicolumn 3 (one line,
but very very very very
very looooong)
@@ -406,28 +388,17 @@
cell
&
cell
- & \multicolumn{3}{p{0.38\DUtablewidth}|}{%
+ & \multicolumn{3}{p{\DUcolumnwidth{0.431}}|}{%
Short multicolumn 4
} \\
\hline
\end{longtable}
-%
-\DUfootnotetext{footnote-1}{footnote-reference-1}{1}{%
-Currently, computed column widths are too wide.
-TODO: Account for the \texttt{\textbackslash{}tabcolsep}.
-}
-For good typographic results experimenting with the \textquotedbl{}width\textquotedbl{} and \textquotedbl{}widths\textquotedbl{}
-options of the \href{https://docutils.sourceforge.io/docs/ref/rst/directives.html\#table}{table directive} may be required. (Unfortunately, the
-interpretation of these values differs between LaTeX writer and HTML
-writer.)
+A problem with the source-derived column widths is that simple tables
+often use no padding while grid tables without padding look cramped:
-Simple tables use often no padding in the source while grid tables
-without padding look clumsy. Setting \texttt{:widths: auto} in the source
-whenever possible is recommended.\DUfootnotemark{footnote-reference-2}{footnote-2}{2}
-
-\setlength{\DUtablewidth}{\linewidth}%
-\begin{longtable}{|p{0.051\DUtablewidth}|p{0.028\DUtablewidth}|p{0.028\DUtablewidth}|p{0.028\DUtablewidth}|}
+\setlength{\DUtablewidth}{\dimexpr\linewidth-5\arrayrulewidth\relax}%
+\begin{longtable}{|p{\DUcolumnwidth{0.100}}|p{\DUcolumnwidth{0.050}}|p{\DUcolumnwidth{0.050}}|p{\DUcolumnwidth{0.050}}|}
\caption{simple table, not padded in the source}\\
\hline
\textbf{%
@@ -454,7 +425,7 @@
} \\
\hline
\endhead
-\multicolumn{4}{r}{... continued on next page} \\
+\multicolumn{4}{p{\DUcolumnwidth{0.250}}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -479,8 +450,8 @@
\hline
\end{longtable}
-\setlength{\DUtablewidth}{\linewidth}%
-\begin{longtable}{|p{0.075\DUtablewidth}|p{0.051\DUtablewidth}|p{0.051\DUtablewidth}|p{0.051\DUtablewidth}|}
+\setlength{\DUtablewidth}{\dimexpr\linewidth-5\arrayrulewidth\relax}%
+\begin{longtable}{|p{\DUcolumnwidth{0.150}}|p{\DUcolumnwidth{0.100}}|p{\DUcolumnwidth{0.100}}|p{\DUcolumnwidth{0.100}}|}
\caption{grid table, padded cells}\\
\hline
\textbf{%
@@ -507,7 +478,7 @@
} \\
\hline
\endhead
-\multicolumn{4}{r}{... continued on next page} \\
+\multicolumn{4}{p{\DUcolumnwidth{0.450}}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -532,6 +503,9 @@
\hline
\end{longtable}
+For better typographic results, setting the \DUroletitlereference{width} and/or
+\DUroletitlereference{widths} options of the \href{https://docutils.sourceforge.io/docs/ref/rst/directives.html\#table}{table directive} is recommended.
+
\begin{longtable}{|l|l|l|l|}
\caption{grid table, auto-width columns}\\
\hline
@@ -543,7 +517,6 @@
\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
\hline
\endhead
-\multicolumn{4}{r}{... continued on next page} \\
\endfoot
\endlastfoot
100 & 2 & 3 & 4 \\
@@ -551,41 +524,35 @@
EUR & b & c & d \\
\hline
\end{longtable}
-%
-\DUfootnotetext{footnote-2}{footnote-reference-2}{2}{%
-Currently, the last column is extra wide because the
-writer adds a hint \textquotedbl{}... continued on next page\textquotedbl{} to longtables with a
-header row. The hint is only shown if the table does not fit on one
-page but always affects the table width.
-}
-If a specific total width is desired, \textquotedbl{}auto\textquotedbl{} column widths fail,
-
-\begin{longtable}{|l|l|l|l|}
-\caption{75\% wide table with \textquotedbl{}auto\textquotedbl{} column widths}\\
+\begin{longtable}{|l|l|}
+\caption{table with multi-row header and \textquotedbl{}auto\textquotedbl{} column-widths}\\
\hline
-\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
+\multirow{2}{*}{\textbf{XXX}} & \textbf{Variable Summary} \\
+\cline{2-2}
+ & \textbf{Description} \\
\hline
\endfirsthead
-\caption[]{75\% wide table with \textquotedbl{}auto\textquotedbl{} column widths (... continued)}\\
+\caption[]{table with multi-row header and \textquotedbl{}auto\textquotedbl{} column-widths (... continued)}\\
\hline
-\textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
+\multirow{2}{*}{\textbf{XXX}} & \textbf{Variable Summary} \\
+\cline{2-2}
+ & \textbf{Description} \\
\hline
\endhead
-\multicolumn{4}{r}{... continued on next page} \\
+\multicolumn{2}{l}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
-100 & 2 & 3 & 4 \\
+\multicolumn{2}{|l|}{multi-column cell} \\
\hline
-EUR & b & c & d \\
-\hline
\end{longtable}
-but \textquotedbl{}grid\textquotedbl{} based or explicit column widths should work:\DUfootnotemark{footnote-reference-3}{footnote-3}{3}
+The \DUroletitlereference{width} option overrides \textquotedbl{}auto\textquotedbl{} \DUroletitlereference{widths} as standard LaTeX tables
+don't have a global width setting:
-\setlength{\DUtablewidth}{0.750\linewidth}%
-\begin{longtable}{|p{0.051\DUtablewidth}|p{0.040\DUtablewidth}|p{0.040\DUtablewidth}|p{0.040\DUtablewidth}|}
-\caption{75\% wide table with explicit column widths}\\
+\setlength{\DUtablewidth}{\dimexpr0.600\linewidth-5\arrayrulewidth\relax}%
+\begin{longtable}{|p{\DUcolumnwidth{0.400}}|p{\DUcolumnwidth{0.200}}|p{\DUcolumnwidth{0.200}}|p{\DUcolumnwidth{0.200}}|}
+\caption{This table has \DUroletitlereference{widths} \textquotedbl{}auto\textquotedbl{} (ignored) and \DUroletitlereference{width} 60\%.}\\
\hline
\textbf{%
A
@@ -598,7 +565,7 @@
} \\
\hline
\endfirsthead
-\caption[]{75\% wide table with explicit column widths (... continued)}\\
+\caption[]{This table has \DUroletitlereference{widths} \textquotedbl{}auto\textquotedbl{} (ignored) and \DUroletitlereference{width} 60\%. (... continued)}\\
\hline
\textbf{%
A
@@ -611,7 +578,7 @@
} \\
\hline
\endhead
-\multicolumn{4}{r}{... continued on next page} \\
+\multicolumn{4}{p{\DUcolumnwidth{1.000}}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -635,45 +602,107 @@
\\
\hline
\end{longtable}
-%
-\DUfootnotetext{footnote-3}{footnote-reference-3}{3}{%
-Bug: The table \textquotedbl{}width\textquotedbl{} option is currently ignored.
+
+
+\subsection{Nested tables%
+ \label{nested-tables}%
}
-\begin{longtable}{|l|l|}
-\caption{table with multirow header and \textquotedbl{}auto\textquotedbl{} column-widths}\\
+\setlength{\DUtablewidth}{\dimexpr\linewidth-3\arrayrulewidth\relax}%
+\begin{longtable*}{|p{\DUcolumnwidth{0.700}}|p{\DUcolumnwidth{0.300}}|}
\hline
-\multirow{2}{*}{\textbf{XXX}} & \textbf{Variable Summary} \\
-\cline{2-2}
- & \textbf{Description} \\
+
+Lorem ipsum dolor sit amet, consectetur
+ &
+adipisicing elit
+ \\
\hline
-\endfirsthead
-\caption[]{table with multirow header and \textquotedbl{}auto\textquotedbl{} column-widths (... continued)}\\
+
+\noindent\makebox[\linewidth][r]{%
+\setlength{\DUtablewidth}{\dimexpr\linewidth-3\arrayrulewidth\relax}%
+\begin{tabular}{|p{\DUcolumnwidth{0.150}}|p{\DUcolumnwidth{0.150}}|}
\hline
-\multirow{2}{*}{\textbf{XXX}} & \textbf{Variable Summary} \\
-\cline{2-2}
- & \textbf{Description} \\
+
+1
+ &
+2
+ \\
\hline
-\endhead
-\multicolumn{2}{r}{... continued on next page} \\
-\endfoot
-\endlastfoot
-\multicolumn{2}{|l|}{multicollumn cell} \\
+\end{tabular}
+}
+ &
+cell 1, 2
+ \\
\hline
-\end{longtable}
+table width depends on parent column
+\noindent\makebox[\linewidth][c]{%
+\setlength{\DUtablewidth}{\dimexpr\linewidth-3\arrayrulewidth\relax}%
+\begin{tabular}{|p{\DUcolumnwidth{0.150}}|p{\DUcolumnwidth{0.150}}|}
+\hline
+
+1
+ &
+2
+ \\
+\hline
+\end{tabular}
+}
+
+better use \textquotedbl{}auto\textquotedbl{} widths, see below
+ &
+same table
+
+\setlength{\DUtablewidth}{\dimexpr\linewidth-3\arrayrulewidth\relax}%
+\begin{tabular}{|p{\DUcolumnwidth{0.150}}|p{\DUcolumnwidth{0.150}}|}
+\hline
+
+1
+ &
+2
+ \\
+\hline
+\end{tabular}
+
+in narrow column
+ \\
+\hline
+
+\noindent\makebox[\linewidth][r]{%
+\begin{tabular}{|l|l|}
+\hline
+1 & 2 \\
+\hline
+\end{tabular}
+}
+
+\begin{description}
+\item[{definition:}]
+list
+
+\end{description}
+ &
+cell 3, 2
+ \\
+\hline
+\end{longtable*}
+
+
\subsection{TODO%
\label{todo}%
}
-Limit the total width of a table to the \texttt{\textbackslash{}linewidth}, unless the table
-width is explicitely specified in the source.
+\begin{itemize}
+\item Tables with multi-paragraph multi-row cells currently fail due to a
+LaTeX limitation (see \url{https://sourceforge.net/p/docutils/bugs/225/}).
-Tables with multi-paragraph multirow cells currently fail due to a LaTeX
-limitation (see \url{https://sourceforge.net/p/docutils/bugs/225/}).
+\item Tweak vertical spacing in table cells containing multiple elements.
+\end{itemize}
+See also \texttt{test/functional/input/data/latex-problematic.txt}.
+
\section{Monospaced non-alphanumeric characters%
\label{monospaced-non-alphanumeric-characters}%
}
@@ -844,8 +873,8 @@
\phantomsection\label{hypertarget-in-plain-text}hypertarget in plain text or in a figure but not in a longtable or
caption:
-\setlength{\DUtablewidth}{\linewidth}%
-\begin{longtable}{|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|p{0.075\DUtablewidth}|}
+\setlength{\DUtablewidth}{\dimexpr\linewidth-4\arrayrulewidth\relax}%
+\begin{longtable}{|p{\DUcolumnwidth{0.150}}|p{\DUcolumnwidth{0.150}}|p{\DUcolumnwidth{0.150}}|}
\caption{Table with %
\label{hypertarget-in-table-title}hypertarget in table title.}\\
\hline
Modified: trunk/docutils/test/functional/expected/latex_memoir.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_memoir.tex 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/functional/expected/latex_memoir.tex 2021-09-30 10:15:45 UTC (rev 8835)
@@ -987,7 +987,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1024,7 +1024,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1061,7 +1061,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1091,7 +1091,6 @@
\textbf{A} & \textbf{B} & \textbf{A or B} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
\endfoot
\endlastfoot
False & False & False \\
@@ -1575,7 +1574,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.24\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1643,7 +1642,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.68\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1703,7 +1702,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.49\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
\textbf{%
Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2021-09-30 10:15:45 UTC (rev 8835)
@@ -988,7 +988,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1025,7 +1025,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1062,7 +1062,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1092,7 +1092,6 @@
\textbf{A} & \textbf{B} & \textbf{A or B} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
\endfoot
\endlastfoot
False & False & False \\
@@ -1597,7 +1596,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.24\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1665,7 +1664,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.68\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1725,7 +1724,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.49\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
\textbf{%
Modified: trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2021-09-30 10:15:45 UTC (rev 8835)
@@ -1022,7 +1022,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1059,7 +1059,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1096,7 +1096,7 @@
} \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.15\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1126,7 +1126,6 @@
\textbf{A} & \textbf{B} & \textbf{A or B} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
\endfoot
\endlastfoot
False & False & False \\
@@ -1635,7 +1634,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.24\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1703,7 +1702,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.68\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
@@ -1763,7 +1762,7 @@
} \\
\hline
\endhead
-\multicolumn{3}{r}{... continued on next page} \\
+\multicolumn{3}{p{0.49\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
\textbf{%
Modified: trunk/docutils/test/functional/input/data/tables_latex.txt
===================================================================
--- trunk/docutils/test/functional/input/data/tables_latex.txt 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/functional/input/data/tables_latex.txt 2021-09-30 10:15:45 UTC (rev 8835)
@@ -4,8 +4,6 @@
In contrast to HTML, LaTeX does not support line-breaks in tables with
"automatic" column widths. Each cell has just one line, paragraphs are
merged (the writer emits a warning).
-To provide for arbitrary cell content, the LaTeX writer defaults to
-specifying column widths computed from the source:
.. table:: problems with "auto" widths
:widths: auto
@@ -20,14 +18,11 @@
| linebreak | |
+-----------+------------------+
-Docutils stores table column widths in the "doctree" (in characters,
-excluding the separator). In the .tex source, column widths are written
-as percent of the ``\linewidth``, computed on the assumption that an
-average text line is 80 characters wide. An allowance added to the stored
-column widths compensates the padding (``\tabcolsep``) added by LaTeX.
-The algorightm provides a working solution in many cases. [#]_
+To provide for arbitrary cell content, the LaTeX writer defaults to
+specifying column widths computed from the source column widths. This
+works sufficiently in many cases:
-.. table:: a table with multi-paragraph multicolumn cells
+.. table:: a table with multi-paragraph multi-column cells
+----------+--------------+---------------------------------+-----------+
| test | **bold hd** | multicolumn 1 | *emph hd* |
@@ -45,18 +40,10 @@
| cell | cell | cell | Short multicolumn 4 |
+----------+--------------+--------------+------------------------------+
-.. [#] Currently, computed column widths are too wide.
- TODO: Account for the ``\tabcolsep``.
-For good typographic results experimenting with the "width" and "widths"
-options of the `table directive`_ may be required. (Unfortunately, the
-interpretation of these values differs between LaTeX writer and HTML
-writer.)
+A problem with the source-derived column widths is that simple tables
+often use no padding while grid tables without padding look cramped:
-Simple tables use often no padding in the source while grid tables
-without padding look clumsy. Setting ``:widths: auto`` in the source
-whenever possible is recommended. [#]_
-
.. table:: simple table, not padded in the source
=== = = =
@@ -76,6 +63,8 @@
| EUR | b | c | d |
+-----+---+---+---+
+For better typographic results, setting the `width` and/or
+`widths` options of the `table directive`_ is recommended.
.. table:: grid table, auto-width columns
:widths: auto
@@ -88,17 +77,23 @@
| EUR | b | c | d |
+-----+---+---+---+
+.. table:: table with multi-row header and "auto" column-widths
+ :widths: auto
-.. [#] Currently, the last column is extra wide because the
- writer adds a hint "... continued on next page" to longtables with a
- header row. The hint is only shown if the table does not fit on one
- page but always affects the table width.
+ +------------+-------------------+
+ | XXX | Variable Summary |
+ | +-------------------+
+ | | Description |
+ +============+===================+
+ | multi-column cell |
+ +--------------------------------+
-If a specific total width is desired, "auto" column widths fail,
+The `width` option overrides "auto" `widths` as standard LaTeX tables
+don't have a global width setting:
-.. table:: 75% wide table with "auto" column widths
+.. table:: This table has `widths` "auto" (ignored) and `width` 60%.
:widths: auto
- :width: 75%
+ :width: 60%
=== = = =
A B C D
@@ -107,41 +102,53 @@
EUR b c d
=== = = =
-but "grid" based or explicit column widths should work: [#]_
+.. _table directive:
+ https://docutils.sourceforge.io/docs/ref/rst/directives.html#table
-.. table:: 75% wide table with explicit column widths
- :width: 75%
- :widths: 3 2 2 2
- === = = =
- A B C D
- === = = =
- 100 2 3 4
- EUR b c d
- === = = =
+Nested tables
+-------------
-.. [#] Bug: The table "width" option is currently ignored.
++-----------------------------------------+-----------------+
+| Lorem ipsum dolor sit amet, consectetur | adipisicing elit|
++-----------------------------------------+-----------------+
+| .. table:: | cell 1, 2 |
+| :align: right | |
+| | |
+| +-----+-----+ | |
+| | 1 | 2 | | |
+| +-----+-----+ | |
++-----------------------------------------+-----------------+
+| table width depends on parent column | same table |
+| | |
+| .. table:: | |
+| :align: center | |
+| | |
+| +-----+-----+ | +-----+-----+ |
+| | 1 | 2 | | | 1 | 2 | |
+| +-----+-----+ | +-----+-----+ |
+| | |
+| better use "auto" widths, see below | in narrow column|
++-----------------------------------------+-----------------+
+| .. table:: | cell 3, 2 |
+| :align: right | |
+| :widths: auto | |
+| | |
+| +-----+-----+ | |
+| | 1 | 2 | | |
+| +-----+-----+ | |
+| | |
+| definition: | |
+| list | |
++-----------------------------------------+-----------------+
-.. table:: table with multirow header and "auto" column-widths
- :widths: auto
- +------------+-------------------+
- | XXX | Variable Summary |
- | +-------------------+
- | | Description |
- +============+===================+
- | multicollumn cell |
- +--------------------------------+
-
TODO
----
-Limit the total width of a table to the ``\linewidth``, unless the table
-width is explicitely specified in the source.
+* Tables with multi-paragraph multi-row cells currently fail due to a
+ LaTeX limitation (see https://sourceforge.net/p/docutils/bugs/225/).
-Tables with multi-paragraph multirow cells currently fail due to a LaTeX
-limitation (see https://sourceforge.net/p/docutils/bugs/225/).
+* Tweak vertical spacing in table cells containing multiple elements.
-
-.. _table directive:
- https://docutils.sourceforge.io/docs/ref/rst/directives.html#table
+See also ``test/functional/input/data/latex-problematic.txt``.
Modified: trunk/docutils/test/functional/tests/latex_cornercases.py
===================================================================
--- trunk/docutils/test/functional/tests/latex_cornercases.py 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/functional/tests/latex_cornercases.py 2021-09-30 10:15:45 UTC (rev 8835)
@@ -8,3 +8,4 @@
writer_name = "latex"
# Extra setting we need
+settings_overrides['legacy_column_widths'] = False
Modified: trunk/docutils/test/test_writers/test_latex2e.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e.py 2021-09-24 13:35:26 UTC (rev 8834)
+++ trunk/docutils/test/test_writers/test_latex2e.py 2021-09-30 10:15:45 UTC (rev 8835)
@@ -875,7 +875,7 @@
} & \\
\hline
\endhead
-\multicolumn{2}{r}{... continued on next page} \\
+\multicolumn{2}{p{0.16\DUtablewidth}}{\raggedleft\ldots continued on next page}\\
\endfoot
\endlastfoot
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|