Skip to content

Drop usage of threeparttable (LaTeX) - #3686

Merged
jfbu merged 8 commits into
sphinx-doc:1.6-releasefrom
jfbu:dropthreeparttable
May 9, 2017
Merged

jfbu merged 8 commits into
sphinx-doc:1.6-releasefrom
jfbu:dropthreeparttable

Conversation

@jfbu

@jfbu jfbu commented May 1, 2017

Copy link
Copy Markdown
Contributor

Subject: LaTeX tables with captions are currently rendered either with longtable or threeparttable (with tabular or tabulary). The threeparttable is thought out to allow table notes, but Sphinx never made usage of this. Besides it produces a caption of the same width of the table itself, but there is no reliable way in LaTeX2e to wrap text around a box of unknown dimensions in a fully automatized way, thus currently, the table is always (like longtable) set in its own paragraph. The user can use :align: docutils option to decide if located left, center or right.

Problem is that threeparttable is loaded for almost no benefits. And captions wrapped to the table width look weird compared to captions of longtable which are wrapped at a fixed maximal width of 4in (it can be customized by length \LTcapwidth).

This PR drops usage of threeparttable, achieves exact same vertical spacing as for longtable and wraps the table caption also to \LTcapwidth space. (by default 4in).

This fixes issue #3532, with code-blocks or figures in tables having their own captions. It was very difficult to fix this without dropping threeparttable, also because via the table templates the user can position the caption before or after the table, but threeparttable does not expect that \caption will be used for anything else than the table caption and redefines it at the start of environment.

I don't know how to best "deprecate" threeparttable: there can not be transition, either we use it or we don't. The user can add its usage in the table templates and then add the loading of the package via the 'preamble' key. A priori the only difference in output for existing documents is that the table caption is not wrapped to the table width but to \LTcapwidth.

Not using threeparttable means all tables are now handled the same, whether by longtable or not for the caption width.

Feature or Bugfix

It fixes bug #3532. Also, using threeparttable appears to me to have been a Sphinx bug from the start, because its most salient features such as table notes were never made used of, and tables were always rendered in their own paragraphs, so wrapping the caption to the table width did not make much sense.

Thus for me it is bug fix. But it is a change for people if they somehow hacked at the LaTeX level the threeparttable to achieve some effect. And it changes the wrapping of table captions when not using longtable. For a long time it was very difficult for Sphinx user to customize tables, table templates make it much easier now but exist for a short time. Thus people using templates in their way can still do it, perhaps only by adding loading of threeparttable and adding their own macros to fix issues such as #3491 as was done in #3504.

Notice also that this PR fixes some complicated issue with \belowcaptionskip and \abovecaptionskip due to threeparttable definitions which did not take into account that multiple \caption commands could be used in the environment.

@jfbu jfbu added this to the 1.6 milestone May 1, 2017
@tk0miya

tk0miya commented May 3, 2017

Copy link
Copy Markdown
Member

+1; As I tried in #3377, dropping it brings us simplicity!

@shimizukawa @shibukawa do you have any comments?
As discussed at #3377, now threeparttable is only used to adjust the width of table captions.

Original (HEAD of 1.6-release):
2017-05-03 16 07 21
(But it has #3532 problem)

With this PR:
2017-05-03 16 07 44

@tk0miya tk0miya mentioned this pull request May 3, 2017
@jfbu

jfbu commented May 3, 2017

Copy link
Copy Markdown
Contributor Author

With a simple modification to this PR, the maximal width of the table caption can be made customizable for example to 80% of available linewidth. Or it could replace usage of longtable \LTcapwidth (default 4inches) to maximum of \linewidth and \LTcapwidth: the longtable only works as full page table but tables with tabular or tabulary can work inside list items. There the 4in width may be too big, in a deeply nested list item. I will think about user interface of \sphinxcaptionof macro.

The defaults of 10pt for abovecaptionskip and 0pt for belowcaptionskip
are not suitable for figures in table cells. By default, this will now
be ``\smallskipamount`` for both, so that the caption can also be
located above figure (currently it is put below by latex writer).
@jfbu

jfbu commented May 3, 2017

Copy link
Copy Markdown
Contributor Author

Now that figure captions are correctly rendered inside table cells, I realized vertical spacing was not good. Thus I pushed new commit 0b2b2d2.

This applies to tables rendered by tabular or tabulary which may occur
inside list items. Also ``\sphinxcaptionof`` admits an optional first
argument, which replaces the ``\LTcapwidth`` default. For example:

    ``\sphinxcaptionof[0.5\linewidth]{table}{...}``

can be used in the tabular/tabulary templates.
@jfbu

jfbu commented May 3, 2017

Copy link
Copy Markdown
Contributor Author

Now added possibility in table template to use \sphinxcaptionof with an optional first argument, for example \sphinxcaptionof[0.75\linewidth]{table}{..} so that if table is deeply nested in some list, or quote, then the caption will not exceed the dimension passed as option. Additionally the caption width is always made at most the available linewidth.

Comment thread sphinx/texinputs/sphinx.sty Outdated
% don't exceed linewidth for the caption width
\ifdim\@tempdima>\linewidth\hsize\linewidth\else\hsize\@tempdima\fi
\def\@captype{#2}%
\capstart % must be after setting \@captype

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is good if caption is above table. But if user positions in table template the \sphinxcaptionof below table, this means a link will bring here, not at start of table. Thus I should abstract and separate a \sphinxtablecapstart for more flexibility.

@jfbu jfbu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With latest commit it becomes very easy for user to modify templates so that caption is below tables, not above. Simply move the caption to desired location and drop the \sphinxaftercaption which serves only for spacing if caption on top of table.

@tk0miya

tk0miya commented May 6, 2017

Copy link
Copy Markdown
Member

LGTM again.
Let's merge this if no response from other maintainers in this weekend.

@jfbu

jfbu commented May 6, 2017 •

Copy link
Copy Markdown
Contributor Author

Thanks! I think this simplifies our maintenance. And thanks to the table templates you created, it is always possible to user to re-use threeparttable is so desired.

It also contains useful thing for in future provide possibility that all captions are below figures and tables if user wants. For literal blocks also. (The situation between above and below for literal blocks is less symmetrical as long as we use framed.sty because it is complex code currently to glue the above caption so that it is never separated by pagebreak; for the below caption this is much less of a TeXnical problem)

@tk0miya

tk0miya commented May 7, 2017

Copy link
Copy Markdown
Member

Note: @shimikawa says "no strong opinion" about this issue (in hack-day).

@jfbu

jfbu commented May 8, 2017

Copy link
Copy Markdown
Contributor Author

Thanks @tk0miya @shimizukawa if no objection I will merge in 24 hours.

@jfbu

jfbu commented May 9, 2017

Copy link
Copy Markdown
Contributor Author

Now merging and the will update CHANGES

@jfbu
jfbu merged commit e9df415 into sphinx-doc:1.6-release May 9, 2017
jfbu added a commit that referenced this pull request May 9, 2017
@jfbu
jfbu deleted the dropthreeparttable branch May 11, 2017 09:47
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants