I'm new to tex and got a problem with a table that exceeds the page, because the content is too wide. I'd expect the table to wrap the text into a new line / new lines, if the text is too long for the tables width.
I guess that this is not a default behaviour. How do I turn it on?
This is my minimal tex code:
\documentclass[12pt,a4paper,oneside,fleqn]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{geometry}
\geometry{a4paper,left=15mm,right=15mm, top=1cm, bottom=2cm}
\usepackage{euler}
\usepackage{graphicx}
\parindent 0pt
\setlength{\abovedisplayskip}{0pt}
\begin{document}
\begin{tabular}[ht]{|l|c|l|}
\hline
a & b & Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\\
\hline
\end{tabular}
\end{document}
Best Answer
You can either fix the column width by specifying a paragraph style
p{<len>}
, or you can use a different tabular environment that stretches according to the contents up to the maximum width of the text block. The latter is provided by thetabularx
package which defines the environmenttabularx
with an additional width-of-table argument, as well as the stretchableX
column specifier.An example of the first suggestion:
An example of the second suggestion:
The
tabularx
approach is an easy way out since you don't have to worry about specifying a column width that exactly matches the remaining column space on the page. However, it is possible to calculate the appropriate value of<len>
when using thep{<len>}
column specifier.