Make tabular span textwidth exactly [duplicate]

Consider this example:

\documentclass{report}
\usepackage{lipsum}
\begin{document}
\begin{tabular}{lll}
A & B & \lipsum[1][1-3]
\end{tabular}
\end{document}


In the output:

the last column goes out of the bounds of the page. I could constrain the last column by using\begin{tabular}{llp{3cm}}. However, it would be more convenient to make the table span textwidth automatically. How to do it?

• tabularx is probably what you are looking for. Jan 19 '19 at 19:30
• you should use table with prescribed width. for example tabular* with p column type or tabularx. Jan 19 '19 at 19:30
• @Zarko, could you please provide an elaborate answer? Jan 19 '19 at 19:33

with tabularx package is simple:

\documentclass{report}
\usepackage{tabularx}             % <---
\usepackage{lipsum}

\noindent
\begin{document}
\begin{tabularx}{\linewidth}{llX}  % table width is determined with \linewidth
% at least one column had to be X type
A & B & \lipsum[66]
\end{tabularx}

\noindent
\begin{tabularx}{\linewidth}{@{} llX @{}} % border \tabcolsep is suppressed
A & B & \lipsum[66]
\end{tabularx}

\begin{table}[htb]                      % table is in float environment
\begin{tabularx}{\linewidth}{@{}llX@{}} % border \tabcolsep is suppressed
A & B & \lipsum[66]
\end{tabularx}
\end{table}

\end{document}