table wrap text cell

LaTeX line break within table cell

StartSearchLaTeX for Beginners F.A.Q. LaTeX faqLaTeX topicsLaTeX course
< two tables side by side     > table landscape

line break within a table cell

Because tables are constant source for questions, here one of the very often asked question: how to get a line break within a table cell?

Problem

By using the default tabular enviroment of LaTeX, there is no automatic line break within a cell. There are only some tricks, that the table will look like a table with line breaks, for example by inserting an addititional line and so on.

Solution

A much more elegant way to solve this problem is using the package tabularx. Here, columns can get a fixed width, which could specified in pt (points) or cm. If the cell entry is wider as the specified cell width an automatic wrapping occurs.

Example

\documentclass{article}

\usepackage{tabularx}

\begin{document}

\begin{tabularx}{8cm}{|X|X|X|X|}
\hline
In this table & each column got the same & width & 2cm \\
\hline
As one could & easy see & the width is & to small for some of the cells  \\
\hline
\end{tabularx}

\end{document}
Output:

Example 2
\documentclass{article}

\usepackage{tabularx}

\begin{document}

\begin{tabularx}{\textwidth}{|X|r|c|l|}
\hline
In this table & each column got the same & width & 2cm \\
\hline
As one could & easy see & the width is & to small for some of the cells  \\
\hline
\end{tabularx}

\end{document}
output:

Here you should also mark the second column with X:
\documentclass{article}

\usepackage{tabularx}

\begin{document}

\begin{tabularx}{\textwidth}{|X|X|c|l|}
\hline
In this table & each column got the same & width & 2cm \\
\hline
As one could & easy see & the width is & to small for some of the cells  \\
\hline
\end{tabularx}

\end{document}
output:

Contact   Privacy Policy   disclosures

accept decline

This website uses cookies and pixel tags to ensure you get the best experience on our website. By using this website, you consent to the use of cookies.learn more about cookies see also our privacy policy