1

I am trying to center a table but it is not formatting well. I have looked at questions like this but none of the answers there seem to solve my problem.

\documentclass[11pt]{article}
\begin{document}
\begin{center}
\begin{tabular}{ | c | c | c | c | c | c | c | c | c | c | c | c | }
    \hline
    Steps & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8 & Trial 9 & Trial 10 \\ \hline
    1 & 1 & 1 & -1 & 1 & 1 & 1 & -1 & -1 & -1 & 1 \\
    2 & 0 & 2 & 0 & 0 & 2 & 0 & -2 & -2 & -2 & 0 \\
    3 & 1 & 1 & -1 & 1 & 3 & 1 & -3 & -1 & -3 & 1 \\
    4 & 0 & 0 & -2 & 2 & 4 & 2 & -4 & 0 & -2 & 2 \\
    5 & 1 & -1 & -3 & 1 & 5 & 3 & -5 & 1 & -1 & 3 \\
    6 & 2 & -2 & -2 & 0 & 6 & 4 & -6 & 0 & -2 & 2 \\
    7 & 1 & -1 & -1 & -1 & 5 & 3 & -7 & -1 & -1 & 1 \\
    8 & 2 & 0 & 0 & -2 & 4 & 4 & -8 & -2 & -2 & 0 \\
    9 & 3 & -1 & -1 & -1 & 3 & 5 & -9 & -1 & -1 & 1 \\
    10 & 2 & 0 & -2 & -2 & 2 & 6 & -8 & -2 & 0 & 0 \\
    11 & 3 & -1 & -1 & -3 & 3 & 5 & -7 & -3 & 1 & 1 \\
    12 & 2 & -2 & -2 & -4 & 4 & 4 & -8 & -4 & 2 & 2 \\
    13 & 1 & -3 & -3 & -3 & 3 & 5 & -9 & -3 & 3 & 3 \\
    14 & 2 & -2 & -4 & -2 & 4 & 4 & -10 & -2 & 4 & 2 \\
    15 & 1 & -3 & -3 & -3 & 3 & 3 & -9 & -1 & 3 & 1 \\
    16 & 0 & -2 & -2 & -4 & 4 & 2 & -8 & -2 & 2 & 0 \\
    17 & 1 & -3 & -1 & -5 & 5 & 3 & -9 & -3 & 3 & -1 \\
    18 & 2 & -4 & -2 & -4 & 6 & 2 & -10 & -4 & 2 & -2 \\
    19 & 3 & -3 & -3 & -5 & 7 & 3 & -11 & -5 & 3 & -3 \\
    20 & 2 & -2 & -4 & -4 & 6 & 2 & -10 & -4 & 2 & -2 \\
    21 & 3 & -1 & -5 & -5 & 5 & 1 & -9 & -5 & 3 & -3 \\
    22 & 2 & -2 & -6 & -6 & 6 & 0 & -8 & -4 & 4 & -2 \\
    23 & 1 & -1 & -7 & -7 & 7 & -1 & -9 & -3 & 3 & -3 \\
    24 & 0 & 0 & -6 & -8 & 6 & -2 & -10 & -4 & 4 & -4 \\
    25 & 1 & -1 & -7 & -9 & 7 & -1 & -9 & -3 & 3 & -3 \\
    26 & 0 & -2 & -6 & -10 & 8 & -2 & -10 & -2 & 4 & -2 \\
    27 & 1 & -3 & -7 & -11 & 7 & -1 & -9 & -1 & 5 & -3 \\
    28 & 0 & -2 & -6 & -10 & 6 & 0 & -8 & 0 & 4 & -4 \\
    29 & -1 & -1 & -7 & -11 & 5 & 1 & -7 & -1 & 3 & -3 \\
    30 & 0 & 0 & -8 & -12 & 4 & 2 & -6 & 0 & 2 & -4 \\
\hline
\end{tabular}
\end{center}
\end{document}

I tried a lot of different styles to format this like \centering instead of \begin{center}...\end{center} but none of them work properly.

In the end, the table looks like this this

What should I do to fix this issue

  • TeX/LaTeX can't center something that is just too wide. Each of your cells has a width of about 1.5cm, having 11 of them this means the table is about 17 cm wide, which is more than the usual \textwidth length (in your standard setting of article.cls) – user31729 May 1 '17 at 14:43
1

With the help of siunitx and booktabs you can get a better result: precise alignment for digits and minus signs where appropriate.

\documentclass[11pt]{article}

\usepackage{booktabs,siunitx}

\begin{document}

\begin{center}
\begin{tabular}{
 @{}
 S[table-format=2.0]
 *{10}{S[table-format=-2.0]}
 @{}
}
\toprule
{Steps} &  \multicolumn{10}{c}{Trial} \\
\cmidrule(l){2-11}
   & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} &{10} \\
\midrule
 1 &   1 &   1 &  -1 &   1 &   1 &   1 &  -1 &  -1 &  -1 &   1 \\
 2 &   0 &   2 &   0 &   0 &   2 &   0 &  -2 &  -2 &  -2 &   0 \\
 3 &   1 &   1 &  -1 &   1 &   3 &   1 &  -3 &  -1 &  -3 &   1 \\
 4 &   0 &   0 &  -2 &   2 &   4 &   2 &  -4 &   0 &  -2 &   2 \\
 5 &   1 &  -1 &  -3 &   1 &   5 &   3 &  -5 &   1 &  -1 &   3 \\
 6 &   2 &  -2 &  -2 &   0 &   6 &   4 &  -6 &   0 &  -2 &   2 \\
 7 &   1 &  -1 &  -1 &  -1 &   5 &   3 &  -7 &  -1 &  -1 &   1 \\
 8 &   2 &   0 &   0 &  -2 &   4 &   4 &  -8 &  -2 &  -2 &   0 \\
 9 &   3 &  -1 &  -1 &  -1 &   3 &   5 &  -9 &  -1 &  -1 &   1 \\
10 &   2 &   0 &  -2 &  -2 &   2 &   6 &  -8 &  -2 &   0 &   0 \\
11 &   3 &  -1 &  -1 &  -3 &   3 &   5 &  -7 &  -3 &   1 &   1 \\
12 &   2 &  -2 &  -2 &  -4 &   4 &   4 &  -8 &  -4 &   2 &   2 \\
13 &   1 &  -3 &  -3 &  -3 &   3 &   5 &  -9 &  -3 &   3 &   3 \\
14 &   2 &  -2 &  -4 &  -2 &   4 &   4 & -10 &  -2 &   4 &   2 \\
15 &   1 &  -3 &  -3 &  -3 &   3 &   3 &  -9 &  -1 &   3 &   1 \\
16 &   0 &  -2 &  -2 &  -4 &   4 &   2 &  -8 &  -2 &   2 &   0 \\
17 &   1 &  -3 &  -1 &  -5 &   5 &   3 &  -9 &  -3 &   3 &  -1 \\
18 &   2 &  -4 &  -2 &  -4 &   6 &   2 & -10 &  -4 &   2 &  -2 \\
19 &   3 &  -3 &  -3 &  -5 &   7 &   3 & -11 &  -5 &   3 &  -3 \\
20 &   2 &  -2 &  -4 &  -4 &   6 &   2 & -10 &  -4 &   2 &  -2 \\
21 &   3 &  -1 &  -5 &  -5 &   5 &   1 &  -9 &  -5 &   3 &  -3 \\
22 &   2 &  -2 &  -6 &  -6 &   6 &   0 &  -8 &  -4 &   4 &  -2 \\
23 &   1 &  -1 &  -7 &  -7 &   7 &  -1 &  -9 &  -3 &   3 &  -3 \\
24 &   0 &   0 &  -6 &  -8 &   6 &  -2 & -10 &  -4 &   4 &  -4 \\
25 &   1 &  -1 &  -7 &  -9 &   7 &  -1 &  -9 &  -3 &   3 &  -3 \\
26 &   0 &  -2 &  -6 & -10 &   8 &  -2 & -10 &  -2 &   4 &  -2 \\
27 &   1 &  -3 &  -7 & -11 &   7 &  -1 &  -9 &  -1 &   5 &  -3 \\
28 &   0 &  -2 &  -6 & -10 &   6 &   0 &  -8 &   0 &   4 &  -4 \\
29 &  -1 &  -1 &  -7 & -11 &   5 &   1 &  -7 &  -1 &   3 &  -3 \\
30 &   0 &   0 &  -8 & -12 &   4 &   2 &  -6 &   0 &   2 &  -4 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}

enter image description here

0

You can use package called geometry to solved your table problem

    \documentclass[11pt]{article}
    \usepackage[left=1cm,right=1cm]{geometry}
    \begin{document}
    \begin{center}
    \begin{tabular}{ | c | c | c | c | c | c | c | c | c | c | c | c | }
           \hline
    Steps & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 & Trial 6 & Trial 7 & Trial 8 & Trial 9 & Trial 10 \\ \hline
    1 & 1 & 1 & -1 & 1 & 1 & 1 & -1 & -1 & -1 & 1 \\
    2 & 0 & 2 & 0 & 0 & 2 & 0 & -2 & -2 & -2 & 0 \\
    3 & 1 & 1 & -1 & 1 & 3 & 1 & -3 & -1 & -3 & 1 \\
    4 & 0 & 0 & -2 & 2 & 4 & 2 & -4 & 0 & -2 & 2 \\
    5 & 1 & -1 & -3 & 1 & 5 & 3 & -5 & 1 & -1 & 3 \\
    6 & 2 & -2 & -2 & 0 & 6 & 4 & -6 & 0 & -2 & 2 \\
    7 & 1 & -1 & -1 & -1 & 5 & 3 & -7 & -1 & -1 & 1 \\
    8 & 2 & 0 & 0 & -2 & 4 & 4 & -8 & -2 & -2 & 0 \\
    9 & 3 & -1 & -1 & -1 & 3 & 5 & -9 & -1 & -1 & 1 \\
    10 & 2 & 0 & -2 & -2 & 2 & 6 & -8 & -2 & 0 & 0 \\
    11 & 3 & -1 & -1 & -3 & 3 & 5 & -7 & -3 & 1 & 1 \\
    12 & 2 & -2 & -2 & -4 & 4 & 4 & -8 & -4 & 2 & 2 \\
    13 & 1 & -3 & -3 & -3 & 3 & 5 & -9 & -3 & 3 & 3 \\
    14 & 2 & -2 & -4 & -2 & 4 & 4 & -10 & -2 & 4 & 2 \\
    15 & 1 & -3 & -3 & -3 & 3 & 3 & -9 & -1 & 3 & 1 \\
    16 & 0 & -2 & -2 & -4 & 4 & 2 & -8 & -2 & 2 & 0 \\
    17 & 1 & -3 & -1 & -5 & 5 & 3 & -9 & -3 & 3 & -1 \\
    18 & 2 & -4 & -2 & -4 & 6 & 2 & -10 & -4 & 2 & -2 \\
    19 & 3 & -3 & -3 & -5 & 7 & 3 & -11 & -5 & 3 & -3 \\
    20 & 2 & -2 & -4 & -4 & 6 & 2 & -10 & -4 & 2 & -2 \\
    21 & 3 & -1 & -5 & -5 & 5 & 1 & -9 & -5 & 3 & -3 \\
    22 & 2 & -2 & -6 & -6 & 6 & 0 & -8 & -4 & 4 & -2 \\
    23 & 1 & -1 & -7 & -7 & 7 & -1 & -9 & -3 & 3 & -3 \\
    24 & 0 & 0 & -6 & -8 & 6 & -2 & -10 & -4 & 4 & -4 \\
    25 & 1 & -1 & -7 & -9 & 7 & -1 & -9 & -3 & 3 & -3 \\
    26 & 0 & -2 & -6 & -10 & 8 & -2 & -10 & -2 & 4 & -2 \\
    27 & 1 & -3 & -7 & -11 & 7 & -1 & -9 & -1 & 5 & -3 \\
    28 & 0 & -2 & -6 & -10 & 6 & 0 & -8 & 0 & 4 & -4 \\
    29 & -1 & -1 & -7 & -11 & 5 & 1 & -7 & -1 & 3 & -3 \\
    30 & 0 & 0 & -8 & -12 & 4 & 2 & -6 & 0 & 2 & -4 \\
    \hline
    \end{tabular}
    \end{center}
    \end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.