[Tex/LaTex] moving the whole word to next line when there is no free space

hyphenationline-breakingtables

Is there any option in tabular that can move the whole word to the next line whenever the length of the word is greater than the fixed cell size?

Currently I use

\begin{tabular}{ | p{2cm} | }

And that results in this format

+---------+
| First t-|
| hing    |
+---------+

However I am looking for this shape

+---------+
| First   |
| thing   |
+---------+

Best Answer

You can use \raggedright:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[american]{babel}
\usepackage{array}

\begin{document}

\begin{tabular}{|p{2cm}|p{2cm}|}
  First longerword & First longerword \\
  Second Thing & Second Thing \\
\end{tabular}

\vspace{\baselineskip}

\begin{tabular}{|>{\raggedright}p{2cm}|>{\raggedright\arraybackslash}p{2cm}|}
  First longerword & First longerword \\
  Second Thing & Second Thing \\
\end{tabular}

\end{document}

The second tabular will include a \raggedright in each cell of the p column, which will avoid the hyphenation.

Note that you need to load the array package for this to work. You also need \arraybackslash in at least the last column to have \\ correctly end the table row.

Output:

output

If you need this for just a few cells, you can also use \raggedright in these cells:

\begin{tabular}{|p{2cm}|p{2cm}|}
  \raggedright First longerword & \raggedright\arraybackslash First longerword \\
  Second Thing & Second Thing \\
\end{tabular}

If it's more than one column, you can also define your own column type:

\newcolumntype{R}{>{\raggedright\arraybackslash}p{2cm}}

\begin{tabular}{|R|R|}
  First longerword & First longerword \\
  Second Thing & Second Thing \\
\end{tabular}