# table too wide for twocolumn-mode document

I have a table which comes outside the text column width into the margin of the paper. How do I make the text in the table align to left ?

 \documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\title{}
\author{}

\begin{document}

\maketitle

\begin{abstract}
abc
\end{abstract}

\section{table}
\begin{table}[h!]
\caption{Top 5 movies recommended by content-based CF algorithm} %title of the table
\centering
% centering table
\begin{tabular}{c r}
% creating eight columns
\hline\hline
%inserting double-line
Movies&\multicolumn{1}{c}{Genre} \\ [0.5ex]
\hline
% inserts single-line
The Flintstones(1994)
& Children's,Comedy\\
% Entering row contents
Son in Law(1974) & Comedy, Horror\\
The Princess Bride(1987) & Action, Adventure, Comedy, Romance\\
Star Wars(1977) & Action, Adventure, Romance, Sci-Fi, War\\
Toy Story(1995)
& Animated, Animated Children's, Comedy\\[1ex] % [1ex] adds vertical space
\hline
% inserts single-line
\end{tabular}
\label{tab:hresult}
\end{table}
\end{document}

This is how it looks :


-
You probably just need to add \noindent. But, can you _please_start including afully compilable MWE including \documentclass and the appropriate packages that sets up the problem, as opposed to code snippets. Then those trying to help can simply cut and paste your MWE and get started on solving problem. –  Peter Grill Nov 16 '12 at 5:26
sorry, did the editing –  princess of persia Nov 16 '12 at 5:30
Thanks, that helps. So, what is the problem. Are you saying the table is too far to the right of the margin? If so, replace the \centering with a \noindent. –  Peter Grill Nov 16 '12 at 5:33
To economize on the table's width, I suggest replacing \begin{tabular}{c r} with \begin{tabular}{@{}c r@{}}. By the way, when I compile your MWE, the width of the table does not exceed the \textwidth parameter. –  Mico Nov 16 '12 at 5:34
As Mico pointed out, the table width looks fine. You can use \usepackage{showframe} to see the page margin. –  mythealias Nov 16 '12 at 5:36

Since you use two-column mode, you should use a table* rather than a table environment. The table* environment spans both columns. A restriction is that these floats can only appear at the top of a page.

By the way, I suggest you use the commands \toprule, \midrule, and \bottomrule of the booktabs package in the tabular environment, rather than \hline and various ad-hoc vertical spacing commands. The following modified form of your MWE shows how these commands may be used.

\documentclass[a4paper,10pt,twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,lipsum}
\begin{document}
\lipsum[1-5] % filler text
\begin{table*}
\caption{Top 5 movies recommended by content-based CF algorithm} \label{tab:hresult}
\centering
\begin{tabular}{@{}ll@{}}
\toprule
Movies & Genre \\
\midrule
The Flintstones (1994) & Children's, Comedy\\
Son in Law (1974) & Comedy, Horror\\
The Princess Bride (1987) & Action, Adventure, Comedy, Romance\\
Star Wars (1977) & Action, Adventure, Romance, Sci-Fi, War\\
Toy Story (1995) & Animated, Animated Children's, Comedy\\
\bottomrule
\end{tabular}
\end{table*}
\lipsum[6-14] % more filler text
\end{document}

-
I increased the amount of filler text to show the two column output below that table, and added the image. –  Peter Grill Nov 16 '12 at 7:50
@PeterGrill - Many thanks for editing my MWE and for providing the image. That was incredibly helpful! –  Mico Nov 16 '12 at 12:59

Here are a bunch of different options for your table:

1. Your original table with \centering.
2. With \noindent (which aligns it with the left margin), and column specification of {@{}c r@{}} which remove the column padding before the first column and after the last column.
3. All column spacing removed with {@{}c@{}r@{}}, just to see the effect (probably not a good idea).
4. Using {@{}c P{1.5in}@{}} which removed the column spacing as per 2, but also uses the p column type for the second column to allow for paragraph wrapping.

## Code:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{showframe}

\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}<{}}%

\newcommand*{\MyTabular}[1]{%
\begin{tabular}{#1}
% creating eight columns
\hline\hline
%inserting double-line
Movies&\multicolumn{1}{c}{Genre} \\ [0.5ex]
\hline
% inserts single-line
The Flintstones(1994)
& Children's, Comedy\\
% Entering row contents
Son in Law(1974) & Comedy, Horror\\
The Princess Bride(1987) & Action, Adventure, Comedy, Romance\\
Star Wars(1977) & Action, Adventure, Romance, Sci-Fi, War\\
Toy Story(1995)
& Animated, Animated Children's, Comedy\\[1ex] % [1ex] adds vertical space
\hline % inserts single-line
\end{tabular}
}%

\begin{document}

\begin{table}[h!]% Keep effect of \centering localized
\centering
\MyTabular{c r}
\end{table}

\begin{table}[h!]
\noindent %
\MyTabular{@{}c r@{}}
\end{table}

\begin{table}[h!]
\noindent %
\MyTabular{@{}c@{}r@{}}
\end{table}

\begin{table}[h!]
\noindent %
\MyTabular{@{}c P{1.5in}@{}}
\end{table}
\end{document}

-
Thanks, I guess will stick to the last one :) –  princess of persia Nov 16 '12 at 5:45