# How to center align the whole table?

I created a table and it starts from the left and goes all the way to right, which looks really skewed. So I want to center align the whole table but couldn't figure out how to do it. I'm new to latex so I don't know how to use other plugin or macros, but I suppose there's a command for this basic functionality. Can anyone tell me?

This is my code:

\documentclass[a4paper, 12pt]{article}
\author{My Name}
\setlength\parindent{0pt}
\begin{document}
\begin{table}[h]
\centering
\large{Something:}
\centerline{Table 1:}
\begin{tabular}{c c}
\hline
1 & 2 \\
3 & 4 \\
5 & 6 \\
7 & 8 \\
\end{tabular}

\large{Table 2}

\begin{tabular}{c c}
\hline
1 & 2 \\
\end{tabular}

\end{table}
\end{document}


Note here my numbers from 1 - 8 and 1,2 in table 2 are actually long text, which are long enough that it goes over the right edge of the paper. How can I fix it?

-
Would this question help Centering a Table ? –  percusse Mar 11 '13 at 23:50
Welcome to tex.sx, It always helps if you provide a complete (small) document that shows the problem. perhaps you are looking for \centering\begin{tabular}{... But it is hard to be sure –  David Carlisle Mar 11 '13 at 23:51
no it doesn't work. The whole table starts from the left and even goes over the page, and \centering command does not help –  guest Mar 11 '13 at 23:52
I added code. Please have a look. Thank you very much. –  guest Mar 11 '13 at 23:56
 \large{Something:} does not make Something large it makes all following text large including the tables, don't do that, set the tables in normal size font. –  David Carlisle Mar 11 '13 at 23:57

You should use \caption and let LaTeX number the tables rather than using \centerline and numbering by hand.

\large does not take an argument so \large{something} makes all the following text large, including the table.

You should never use [h] Just using [h] on its own is really an error; LaTeX issues a warning and changes it to [th] but even then it makes it very likely the table goes to the end of the document as it disallows p positioning (float pages).

Finally You provide an example that shows the problem you have. c columns are like \mbox and single line you want p columns that allow line breaking to a specified width. Then the columns are narrower and the table fits on a page and can be centred. Note changing c to p was one of the suggestions in the linked question about making a table smaller.

\documentclass[a4paper, 12pt]{article}
\author{My Name}
\setlength\parindent{0pt}

\begin{document}

\begin{table}
\centering
Something:

\caption{blah blah}

\smallskip

\begin{tabular}{c c}
\hline
1 & 2 \\
3 & 4 \\
5 & 6 \\
7 & 8 \\
\end{tabular}

\caption{blah blah}

\smallskip
\begin{tabular}{p{3cm} p{3cm}}
\hline
This is a very long text and it goes over the edge & and I can not figure out how to align it at the center \\
\end{tabular}

\end{table}

\end{document}

\documentclass[a4paper, 12pt]{article}
\author{My Name}
\setlength\parindent{0pt}

\begin{document}

\begin{table}
\centering
Something:

\caption{blah blah}

\smallskip

\begin{tabular}{c c}
\hline
1 & 2 \\
3 & 4 \\
5 & 6 \\
7 & 8 \\
\end{tabular}

\caption{blah blah}

\smallskip
\begin{tabular}{c c}
\hline
1 & 2 \\
\end{tabular}

\end{table}

\end{document}

-
That's not my problem. My problem is the table is positioned incorrectly. I want it to be at the center of the page instead of starting from the left and going over the right edge. –  guest Mar 12 '13 at 0:04
See what happens if you change line "1 & 2 \\" to "This is a very long text and it goes over the edge & and I can not figure out how to align it at the center \\". And you will see my problem –  guest Mar 12 '13 at 0:09
It only goes over the right edge if it is wider than the page. If it is wider than the page it can not be centred. Arggg your problem is not as you described at all, I will update my answer –  David Carlisle Mar 12 '13 at 0:10
Great! That works! Thank you very much and sorry for my description. I'm new to latex and do not know how to describe the problem professionally. –  guest Mar 12 '13 at 0:18
@guest It's best not to describe it at all but to provide an example that demonstrates it. –  David Carlisle Mar 12 '13 at 0:20

Try surrounding the whole thing with

\begin{center}
\end{center}

-
does not work. The table starts from the left margin and even goes over the right edge of the page. I tried many ways but still cannot figure out. –  guest Mar 11 '13 at 23:53
If the entire table is going over the edge you may need to decrease the size of font/table in order to make it fit, and then align it how you want. See this page for that...tex.stackexchange.com/questions/4139/… –  david Mar 11 '13 at 23:58
I'm using the default 12pt size. If I make it smaller enough to center the table I can't read my document. –  guest Mar 12 '13 at 0:01
well I'll +1 as you answered the question asked, even if it wasn't the OP's problem as it finally turned out:-) –  David Carlisle Mar 12 '13 at 0:37
It's not recommendable together with a table environment. Would you perhaps consider removing the suggestion? –  Stefan Kottwitz Mar 13 '13 at 14:15

Use \begin{center} like this. It will work. If you don't want to align content to center try changing |c| to |p{50mm}|.

\begin{table}[ht]
\caption{caption}
\begin{center}
\begin{tabular}{| c | c |}

...

\end{tabular}
\end{center}
\label{label}
\end{table}

-