Repository navigation
Drop usage of threeparttable (LaTeX) - #3686
Conversation
|
+1; As I tried in #3377, dropping it brings us simplicity! @shimizukawa @shibukawa do you have any comments? Original (HEAD of 1.6-release): |
|
With a simple modification to this PR, the maximal width of the table caption can be made customizable for example to |
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).
|
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.
|
Now added possibility in table template to use |
| % 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 |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
LGTM again. |
|
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 |
|
Note: @shimikawa says "no strong opinion" about this issue (in hack-day). |
|
Thanks @tk0miya @shimizukawa if no objection I will merge in 24 hours. |
|
Now merging and the will update CHANGES |


Subject: LaTeX tables with captions are currently rendered either with
longtableorthreeparttable(with tabular or tabulary). Thethreeparttableis 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\LTcapwidthspace. (by default4in).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
\captionwill 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
threeparttableand 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
\belowcaptionskipand\abovecaptionskipdue tothreeparttabledefinitions which did not take into account that multiple\captioncommands could be used in the environment.