[Tex/LaTex] Set maximum width of table

tablestabularx

I am trying to create a table that fits on the page and is not wider even though the contens are. So I used tabularx:

\begin{table}[H]
\centering    
\begin{tabularx}{\textwidth}{cccX}
    1 & 2 & 3 &    4 \\ \hline      
    from & INOUT & Wavelength & very long text very long text very long text very long text very long text very long text very long text very long text                 
\end{tabularx}
\end{table}

This works but now the table is always as wide as my page even when the content would allow a smaller table. So I would like to set the maximum table width and not a constant width. Is there something that can do this?

Regards

Best Answer

If you use tabulary instead of tabularx and use L or S instead of X, then it will do exactly this.

Related Question