[Tex/LaTex] Table which increases row size when text is too big

pdftextables

I have a simple table:

    \begin{table}[]

        \begin{tabular}{c|c|c|c|c|c|c|c|}
            \cline{2-7} & 
            \multicolumn{1}{p{2.7cm}|}{RIGHT} & 
            \multicolumn{1}{c|}{LEFT}&   
            \multicolumn{1}{c|}{LEFT}&  
            \multicolumn{1}{c|}{LEFT}&
            \multicolumn{1}{c|}{LEFT}& 
            \multicolumn{1}{c|}{LEFT} \\ \hline

            \multicolumn{1}{|c|}{test1} & 1 & 1 &1 & 1 & 1 &1\\ \hline
            \multicolumn{1}{|c|}{test2} & 1 & 1 &1 & 1 & 1 &1\\ \hline
            \multicolumn{1}{|c|}{test2} & 1 & 1 &1 & 1 & 1 &1\\ \hline
        \end{tabular}

\end{table}

Looks like this:

enter image description here

I am trying to make this table to fit in the page and to increase the row size when text is too long but I didn't manage to do that.

In the above table if in a cell I insert a long text it will look like this:
enter image description here

Someone help me to resize my table with this:

\newcommand*{\ResizeTableIfTooBig}[1]{%
%% #1 = table
\savebox{\MyTable}{#1}%
\ifdim\wd\MyTable<\linewidth
\usebox{\MyTable}%
\else
\resizebox{\textwidth}{!}{\usebox{\MyTable}}%
\fi
}%

The problem is that this snapshot just scales the table and when text from cells is too long the font is very small.

What will help me is a table with 7 columns which will not come out of the paper and will create a new line when the text is too long for each column(without scaling font).
Something like this:
enter image description here

Best Answer

You can use tabularx to make your table fit line width:

\documentclass{article}
\usepackage{tabularx, lipsum}
\setlength{\extrarowheight}{2pt}

\begin{document}

\lipsum[11]
\begin{table}[!htb]
    \begin{tabularx}{\linewidth}{|c|>{\centering}p{2.7cm}|*{5}{>{\centering\arraybackslash}X|}}
        \cline{2-7}
      \multicolumn{1}{c|}{} & RIGHT & LEFT & LEFT & LEFT & LEFT & LEFT \\ 
       \hline
       test1 & 1 & 1 &1 & 1 & 1 & I vel II vel III vel \&c. \\ \hline
       test2 & 1 & 1 &1 & 1 & 1 &1 \\ \hline
       test2 & 1 & 1 &1 & 1 & 1 &1 \\ \hline
    \end{tabularx}
\end{table}

\end{document} 

enter image description here

Related Question