[Tex/LaTex] How to adjust table width to 1 column in 2 column document

tables

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 including t. Then you have specified a tabularx 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 specifier X specified in tabularx I would recommend to instead use tabular. In the example below I have included some lipsum text to show the table plpacement clearer.

\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}
%%
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
%%%
\begin{table*} [ht]
  \centering
  \caption{Caption for the table.}
  \label{tab:table1}
  % \resizebox{\columnwidth}{!}{  
    \begin{tabular}{cccccc} %{\columnwidth}{cccccc}
      \toprule
      &                               & first col         & second col        & third col     & forth col  \\
      first row                       &                   & \xmark            & \xmark        & \xmark      \\

      % \midrule
      % prettifies & the & content \\

      \bottomrule
    \end{tabular}
  %}
\end{table*}

\lipsum[4-13]

\end{document}

enter image description here

Related Question