# how to make tex4ht center a long table as it does with table?

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

\documentclass[11pt]{article}%
\usepackage{float}
\usepackage{longtable}
\begin{document}

This is my table

\begin{table}[H]
\centering
\begin{tabular}[c]{|c|c|}\hline
A & B \\\hline
853.075 (sec) & 43.711 (sec)\\\hline
14.218 (minutes) & 0.729 (minutes)\\\hline
\end{tabular}
%\caption{Total real time used to solve all problems}
\end{table}

my table is done

This is my long table

\begin{longtable}[c]{|c|c|}\hline
A & B \\\hline
853.075 (sec) & 43.711 (sec)\\\hline
14.218 (minutes) & 0.729 (minutes)\\\hline
\end{longtable}

my long table is done

\end{document}


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

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

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. – David Carlisle Jan 30 '19 at 20:49
• but you added \begin{center} which also does nothing useful for longtable. – David Carlisle Jan 30 '19 at 21:23
• @DavidCarlisle Ok, removed \begin{center} from long table also. Thaks. – Nasser Jan 30 '19 at 21:25

## 1 Answer

This is easy to fix using bit CSS:

\Preamble{xhtml}
\Css{table.longtable{margin-left: auto;margin-right:auto;}}
\begin{document}
\EndPreamble


The result:

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 '19 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 '19 at 1:36
• @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 '19 at 15:44