I need to create a table in one column. It needs to be adjusted to fit in. For example, the text can be in two rows. The table lines are fit in one column. but the text excceds the column width. How can I make the table text expands to next row instead exceeding the column width? This is the minimal test code.
\documentclass[letterpaper,twocolumn,10pt]{article}
\usepackage{graphicx}
\usepackage{array,tabularx}
\usepackage{multirow,booktabs} %for the table
\usepackage{pifont}% cross and match marks. http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\usepackage{array,tabularx}
\begin{document}
\begin{table*} [h!]
%\centering
\caption{Caption for the table.}
\label{tab:table1}
\resizebox{\columnwidth}{!}{
\begin{tabularx} {\columnwidth}{cccccc} %{\columnwidth}{cccccc}
\toprule
& & first col & second col & third col & forth col \\
first row & & \xmark & \xmark & \xmark \\
%\midrule
%prettifies & the & content \\
\bottomrule
\end{tabularx}
}
\end{table*}
\end{document}
Best Answer
You have specified
table*
which is a table that spans two columns. This can only be set on top of page spo you should hace the argument[t]
instead, or at least something includingt
. Then you have specified atabularx
of size\columnwidth
which means the table has that width. That is the reason the lines are one column. Since the text is wider it does not fit in the table. Furthermore, since you do not use the column specifierX
specified intabularx
I would recommend to instead usetabular
. In the example below I have included some lipsum text to show the table plpacement clearer.