when using \centering option in table, and then using either tabular or longtable then both come out centered in PDF as expected.

But in tex4ht, only the tabular comes out centered in middle of the web page, while the longtable is not centered and remained to the left edge of the webpage.

Here is a MWE


This is my table

A & B \\\hline
853.075 (sec) & 43.711 (sec)\\\hline
14.218 (minutes) & 0.729 (minutes)\\\hline
%\caption{Total real time used to solve all problems}

my table is done

This is my long table

A & B \\\hline
853.075 (sec) & 43.711 (sec)\\\hline
14.218 (minutes) & 0.729 (minutes)\\\hline

my long table is done


Compiled using lualatex foo.tex shows that both are centered in middle of page

Mathematica graphics

Using make4ht foo.tex "htm" only the tabular is centered:

Mathematica graphics

How to make longtable be centered as well?

  • \centering has no effect on a longtable and a longtable inside a table can not do anything useful, so remove the \begin[table}[H] and \centering. Jan 30, 2019 at 20:49
  • but you added \begin{center} which also does nothing useful for longtable. Jan 30, 2019 at 21:23
  • @DavidCarlisle Ok, removed \begin{center} from long table also. Thaks.
    – Nasser
    Jan 30, 2019 at 21:25

1 Answer 1


This is easy to fix using bit CSS:

\Css{table.longtable{margin-left: auto;margin-right:auto;}}

The result:

enter image description here

I've also updated the tex4ht sources.

  • Nice fix (working), but now It gets centered always (even if I \begin{longtable}[l] or \begin{longtable} without specifying the [c]).
    – Tinmarino
    Nov 17, 2019 at 1:21
  • Of course, I use this answer for the revert solution. After a quick lookaround at text4ht and its 9 contributors, thanks a lot for your contribution #michal.h21.
    – Tinmarino
    Nov 17, 2019 at 1:36
  • 1
    @tinmarino thans for your kind words. the table cell alignment is based on the table specifiers by default. to suppress that, you can use something like \Css{ table.longtable td{text-align:center !important;}}.
    – michal.h21
    Nov 17, 2019 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .