[Tex/LaTex] centering content with \oddsidemargin

marginstabularx

I have a big document only composed of tabular or tabularx (product specifications) and I would like to center them in the whole document. Those tabular are considerable, most of them use the full width availiable (in this case it's a basic portrait A4 paper), so 21cm.

Examples:

\begin{tabularx}{21cm}{X X X}
...
\end{tabularx}
\begin{tabularx}{15cm}{X X X}
...
\end{tabularx}
\begin{tabularx}{20.5cm}{X X X}
...
\end{tabularx}

When I started making all the tabulars, I realize that a tabular have a kind of margin around it and as the space is precious to me, I decide to remove all margins in the document. To do that, I use the command \setlength{\oddsidemargin}{-1.22in} (found here) which shift the whole content of the document a little bit to the left to compensate the tabular left margin.

But now, when I try to center all tabulars (because some of them are smaller) in the page using \centering or any other centering technic, there are not centered. They are in fact but with an additional 1.22in on the left, which is exactly the length specified in \setlength{\oddsidemargin}{-1.22in}.

If I comment %\setlength{\oddsidemargin}{-1.22in}, most of my tabulars exceed on the right and are then truncated (so some end of text are not displayed)

So I have severals questions at this point :

  • Did I wrongly remove the margin of my document ? Because here I am not removing them but compensating them in fact.

  • Is it possible to do without \setlength{\oddsidemargin}{-1.22in} to be able to use the \centering command in the correct way ?

  • If not, is there any way to disable or set to 0 the right margin (and not the padding like in HTML) of a tabular ?

Thanks,

Note 1 : I did not specified any \textwidth, all the original with \documentclass{article}[10pt,a4paper,sans]

Note 2 : I use those commands to remove margins and other stuff :

\setlength{\topmargin}{-1.4in}
\setlength{\oddsidemargin}{-1.22in}
\setlength{\marginparwidth}{0in}
\setlength{\hoffset}{0in}
\setlength{\voffset}{0in}

Best Answer

A skeleton for a document with horizontally centered tables that might occupy the full text width would be:

\documentclass[a4paper]{article}
\usepackage[
  hmargin=0mm, % Remove left and right margin
  % Set vertical margin or whatever
]{geometry}
\usepackage{tabularx}

\setlength{\parindent}{0pt}% No indentation of first lines in paragraphs
\setlength{\parskip}{2ex minus 1ex plus 4ex}% Vertical space between paragraphs

\begin{document}
\centering

\begin{tabularx}{21cm}{X X X}
  ...
\end{tabularx}

\begin{tabularx}{15cm}{X X X}
  ...
\end{tabularx}

\begin{tabularx}{20.5cm}{X X X}
  ...
\end{tabularx}
\end{document}

The empty lines between the environments tabularx are important. Then each table is set inside a new paragraph. The space between these paragraphs can be configured by \parskip, see the preamble.