Skip to content

Figure or literal block captions in cells of short tables cause havoc in PDF output #3532

Closed

Description

@jfbu

Subject: when a table cell contains a figure directive, and is rendered in LaTeX via threeparttable, the figure caption is used as table caption and there are other nefarious consequences.

Error logs / results

capture du 2017-03-09 14-51-45

Reproducible project / your project

Welcome to FOO's documentation!
===============================

First table:

.. list-table:: This is a table
   :widths: auto
   :header-rows: 1

   * - header 1
     - header 2
   * - cell
     - .. figure:: more.png

          No, I am not the table caption!


Second table (uses longtable):

.. cssclass:: longtable

.. list-table:: This is a table
   :widths: auto
   :header-rows: 1

   * - header 1
     - header 2
   * - cell
     - .. figure:: more.png

          I told you I was the figure caption!

This second table does use the figure caption (but has its problems, too).

Third table:

.. list-table:: This is a table
   :widths: auto
   :header-rows: 1

   * - header 1
     - header 2
   * - cell
     - .. code-block:: python
          :caption: No, I am not the table caption!

          def foo(x):
              return None

Fourth table (uses longtable):

.. cssclass:: longtable

.. list-table:: This is a table
   :widths: auto
   :header-rows: 1

   * - header 1
     - header 2
   * - cell
     - .. code-block:: python
          :caption: I told you I was the code-block caption!

          def foo(x):
              return None

This fourth table does use correctly the code-block caption.

Screenshot above is with current HEAD of master. Similar result with 1.5.3., but as its vertical spacing is not so good, I preferred master for not distracting from issue.

Details

The Sphinx LaTeX takes precautions for figures regarding the \caption macro, so it works in longtable environment despite its redefintion of \caption but threeparttable redefines rather \@caption, not \caption so in this environment, the Sphinx prophylactic measures fail.

Similar issues exist with literal-blocks or anything using \caption.

capture du 2017-03-09 15-11-25

Standard LaTeX does not allow such things as \caption in a table cell, which explains table packages take no special precautions.

Environment info

  • OS: Linux Ubuntu 16.04
  • Python version: 3.5.2
  • Sphinx version: 1.5.3 and master branch
  • TeXLive 2016, somewhat up-to-date

Activity

  1. changed the title [-]Figure or literal block captions in table cells cause havoc in PDF output[/-] [+]Figure or literal block captions in cells of short tables cause havoc in PDF output[/+] on Mar 9, 2017
  2. self-assigned this
    on Mar 11, 2017
  3. added this to the 1.6 milestone on Apr 4, 2017
  4. added a commit that references this issue on May 1, 2017
    5c87879
  5. jfbu commented on May 9, 2017

    @jfbu
    ContributorAuthor

    Fixed by #3686 merge (includes 5c87879)

  6. locked as resolved and limited conversation to collaborators on Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions