0

I am trying to write a table that has 4 columns. However the 4th column is too large and i am writting texts inside this column and then the table goes outside the page. I would like to break a line using tabular everytime the text gets too large. This is an example:

\begin{table}     
\begin{tabular}{llll}
\hline\noalign{\smallskip}
Study & CNN & Task & Optimization \\
\noalign{\smallskip}\hline\noalign{\smallskip}
authors &  CNN and Extreme Learning Machine & Image Classification & Ensemble methods with CNN.    
\noalign{\smallskip}\hline
\end{tabular}
\end{table}

2 Answers2

1

You could experiment with the p type column which allows auto line breaks

reference from -- https://tex.stackexchange.com/a/166746/197451

enter image description here

\begin{table}     
\begin{tabular}{llll}
\hline\noalign{\smallskip}
Study & CNN & Task & Optimization \\
\noalign{\smallskip}\hline\noalign{\smallskip}
authors &  CNN and Extreme Learning Machine & Image Classification & \multicolumn{1}{p{4cm}|}{\raggedright At oprette en server med bestemte regler som tillader folk at spille sammen. More Text more text More Text}  \\ 
\noalign{\smallskip}\hline
\end{tabular}
\end{table}
js bibra
  • 21,280
0

To make your code compilable, a \\ right before the last \noalign{\smallskip}\hline is missing. Having added this missing piece of code, let's focus on improving the output. With the help of the tabularx package you can easily make sure a table fits into the textwidth and horizontal lines from the booktabs package could be used instead of \noalign{\smallskip}\hline. Applying thouse changes, one ends up with:

enter image description here

Depending on your documentclass, the margin and font sizes as well as the individual contents of the table, you may want to alter the width of the X type columns. Table layout with tabularx (column widths: 50%|25%|25%) contains useful information on that. Text in narrower columns often looks better left aligned instead of justified and if you want left-aligned text in your X type columns, you could use >{\raggedright\arraybackslash}X instead of X.

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}

\begin{table}
\begin{tabularx}{\linewidth}{lXlX} \toprule Study & CNN & Task & Optimization \ \midrule authors & CNN and Extreme Learning Machine & Image Classification & Ensemble methods with CNN.\
\bottomrule \end{tabularx} \end{table}

\end{document}

leandriis
  • 62,593