# How can I center all tables in a document?

## Background

Would like to center all tables within floats, without having to add \centering to each table.

## Ideas

Tried the following:

\let\originaltabular\tabular
\renewcommand\tabular{\centering\originaltabular}


It compiles, but the tables remain left-justified.

## Question

How would you edit the Preamble of a LyX document to make all the floating tables be centred?

-
–  Ciro Santilli Mar 13 at 9:16

If you would like to center all tabular environments, I would recommend to create your own environment with a different name, which calls tabular. You could use that instead of redefining tabular itself.

But no problem, this can be done. Just use \renewenvironment, for example:

\let\originaltabular\tabular
\let\endoriginaltabular\endtabular
\renewenvironment{tabular}[1]{%
\begingroup%
\centering%
\originaltabular{#1}}%
{\endoriginaltabular\endgroup}


You could redefine the floating table environment very similar:

\let\originaltable\table
\let\endoriginaltable\endtable
\renewenvironment{table}[1][ht]{%
\originaltable[#1]
\centering}%
{\endoriginaltable}


You could also use etoolbox to patch the table environment or append \centering to the definition this way:

\makeatletter
\makeatother


or

\expandafter\def\expandafter\table\expandafter{\table\centering}

-

In the Lyx list, I learned that the following in the preamble will automatically center the contents of figures and tables in floats. It works for me.

\usepackage{ifthen}
\renewenvironment{figure}[1][]{%
\ifthenelse{\equal{#1}{}}{%
\@float{figure}
}{%
\@float{figure}[#1]%
}%
\centering
}{%
\end@float
}

\renewenvironment{table}[1][]{%
\ifthenelse{\equal{#1}{}}{%
\@float{table}
}{%
\@float{table}[#1]%
}%
\centering
}{%
\end@float
}

-

I didn't test this with LyX, but \usepackage{floatrow} also centers the contents of floats. (The justification is configurable, but \centering is floatrow's default behaviour.)

-
You have to use floatbox code to use floatrow. LyX adds floats as \begin_inset Float table; were I hand-coding this in LaTeX, I could try it. –  Dave Jarvis Nov 27 '10 at 19:47