[Tex/LaTex] Table width equal line width

tablestwo-columnwidth

I generated this table but it's width exceeds the line width as i am working in two column paper And i need it to fit only in one column, Any help ?

enter image description here

\begin{table}[t]
\centering
\begin{tabular}{|c|c|c|}
\hline
Generated Cluster Number & Real Cluster Number & Ratio of mapped spikes \\
\hline
         2 &          3 &     0.4233 \\
\hline
         3 &          2 &     0.3545 \\
\hline
         4 &          1 &     0.8463 \\
\hline
         5 &          1 &     0.3432 \\
\hline
         6 &          3 &     0.6345 \\
\hline
         7 &          2 &     0.2349 \\
\hline
         8 &          2 &     0.4267 \\
\hline
\end{tabular}
\label{tab:template}
\end{table}

Best Answer

You can use the starred version of tabular environment and a p{} modifier for column alignment with custom size, based on \linewidth.

\documentclass[twocolumn]{article}
\usepackage{booktabs}
\usepackage{lipsum}
\begin{document}
\begin{table}[t]
\centering\small
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}p{0.3\linewidth}p{0.3\linewidth}p{0.3\linewidth}@{}}
\toprule
Generated Cluster Number & Real Cluster Number & Ratio of mapped spikes \\
\midrule
         2 &          3 &     0.4233 \\
         3 &          2 &     0.3545 \\
         4 &          1 &     0.8463 \\
         5 &          1 &     0.3432 \\
         6 &          3 &     0.6345 \\
         7 &          2 &     0.2349 \\
         8 &          2 &     0.4267 \\
\bottomrule
\end{tabular*}
\label{tab:template}
\end{table}
\lipsum[1-5]
\end{document}

enter image description here

Related Question