Bug in Table Headers sphinx_rtd_theme

142 views
Skip to first unread message

Dirk Baumbach

unread,
Jan 6, 2020, 5:28:28 AM1/6/20
to sphinx-users
Hello,

i have this weird issue, an additional newline is added in every header cell of a table:


The Code:

.. list-table::
   :header-rows: 1
   :align: left

   * - Inport
     - OutDataTypeStr
     - OutMin
     - OutMax
     - PortDimensions
     - SampleTime
     - SignalType
     - Description
   * - u1
     - Inherit: auto
     - []
     - []
     - -1
     - -1
     - real
     - This is the dividend.
   * - u2
     - Inherit: auto
     - []
     - []
     - -1
     - -1
     - real
     - This is the divisor.


It doesn't matter with which directive the table was created. It happens with all types (simple table, list-table, csv-table, ...). I know this must be a bug, because all example rtd-documentations don't have this issue:


I'm using the latest versions of both sphinx and the rtd-theme

I didn't found anything like this on google so far.

Does anyone have experience with this issue?

Sincerly
Dirk


Libor Jelinek

unread,
Jan 6, 2020, 7:14:18 AM1/6/20
to sphinx...@googlegroups.com
Hello Dirk!
I've also noticed that my tables header rows got taller. But it's not related to RTD theme. If you look at generated source code, Sphinx inserts header in <p> that has margin-bottom: 24px:

image.png

For example old Sphinx 1.8.1 from Sep 2, 2018 doesn't wrap headers in <p>. Docs you posted as example must be built with such old Sphinx. Current version current 2.3.1. inserts <p>. Don't ask me why.

Workaround if it's critical, use styles to remove margins for <p> inside <th>.

Libor

po 6. 1. 2020 v 11:28 odesílatel 'Dirk Baumbach' via sphinx-users <sphinx...@googlegroups.com> napsal:
--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/c591b21e-c36b-41e3-a601-8443980e571b%40googlegroups.com.
Message has been deleted

Dirk Baumbach

unread,
Jan 6, 2020, 7:55:05 AM1/6/20
to sphinx-users
Thanks for this plausible answer!

I am not very familiar with CSS. Do you have a sample code snippet on how to remove the <p> margin in the table header tag?

Libor Jelinek

unread,
Jan 6, 2020, 8:20:16 AM1/6/20
to sphinx...@googlegroups.com
My pleasure! There is multiple ways. If you don't already have own CSS, create one.

1. In your conf.py add line

   html_css_files = ['custom.css']

2. Create "custom.css" inside static dir (usually "_static" but setting html_static_path can change static dir name) with the content:

   th.head p {
      margin: 0;
   }

po 6. 1. 2020 v 13:55 odesílatel 'Dirk Baumbach' via sphinx-users <sphinx...@googlegroups.com> napsal:
Thanks for this plausible answer!

I am not very familiar with CSS. Do you have a sample code snippet on how to remove the <p> margin in the table header tag?

--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.

Komiya Takeshi

unread,
Jan 6, 2020, 10:16:49 AM1/6/20
to sphinx...@googlegroups.com
Hi Dirk,

Since Sphinx-2.0, the default HTML writer has been changed to HTML5 writer. It inserts <p> tag to some location. I guess sphinx_rtd_theme does not work well with HTML5 writer. As a workaround, you can use old HTML4 writer with `html4_writer = True` setting in your conf.py. If possible, please report this into sphinx_rtd_theme project. I hope it will support HTML5 writer.

Thanks,
Takeshi KOMIYA

2020年1月6日(月) 21:14 Libor Jelinek <ljel...@virtage.com>:

Jared Dillard

unread,
Jan 6, 2020, 3:51:03 PM1/6/20
to sphinx...@googlegroups.com
There is a project board on github to fix the issues with sphinx 2 and the RTD theme: https://github.com/readthedocs/sphinx_rtd_theme/projects/1

Komiya Takeshi

unread,
Jan 7, 2020, 11:11:38 AM1/7/20
to sphinx...@googlegroups.com
Good to hear!

2020年1月7日(火) 5:51 Jared Dillard <jared....@gmail.com>:

Libor Jelinek

unread,
Jan 8, 2020, 7:32:06 AM1/8/20
to sphinx...@googlegroups.com
I'm sorry but I still see it as a bug of HTML5 writer, themes may only workaround it with CSS. No human will code with extra <p> as in generated output (<th><p>Column heading</p></th>). Should that be reported rather to Docutils / Sphinx (not sure who supply HTML5 writer)?

Libor


út 7. 1. 2020 v 17:11 odesílatel Komiya Takeshi <i.tk...@gmail.com> napsal:

Komiya Takeshi

unread,
Jan 8, 2020, 8:52:27 AM1/8/20
to sphinx...@googlegroups.com
Hi,

This behavior comes from docutils' implementation. So it would be better to post opinions to docutils-sig.

IMO, this is not a bug. In reST syntax, we can put one or more paragraphs in table header. To supports each case consistently, docutils always generates paragraph tag in HTML5 mode. So far, in HTML4 mode, it strips paragraph tag in case of table header contains only one paragraph node. But it is a bit difficult to add styles in CSS to me. +1 for current behavior.


2020年1月8日(水) 21:32 Libor Jelinek <ljel...@virtage.com>:

Libor Jelinek

unread,
Jan 8, 2020, 9:15:10 AM1/8/20
to sphinx...@googlegroups.com
Writer used in Sphinx >= 2 by default is this one https://docutils.sourceforge.io/docs/user/html.html#html5-polyglot?


st 8. 1. 2020 v 14:52 odesílatel Komiya Takeshi <i.tk...@gmail.com> napsal:

Komiya Takeshi

unread,
Jan 8, 2020, 9:44:21 AM1/8/20
to sphinx...@googlegroups.com
Correctly, Sphinx's HTML5 writer inherits html5-polyglot writer. It adds original features. But we does not modify about paragraphs into html5-polyglot. So almost yes.

2020年1月8日(水) 23:15 Libor Jelinek <ljel...@virtage.com>:
Reply all
Reply to author
Forward
0 new messages