4

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

Mathematica graphics

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

Mathematica graphics

How to make longtable be centered as well?

3
  • \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

4

This is easy to fix using bit CSS:

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

The result:

enter image description here

I've also updated the tex4ht sources.

3
  • 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 .