I am generating some table as follow:
\begin{tabular}[l]{|l|l|l|}
\hline
Input & Output& Action return \\
\hline
\hline
DNF & simulation & jsp\\
\hline
\end{tabular}
How can can I give this table the same width as the text width? For graphic I use
[width=\textwidth]
But this doesn't work for table.
Use p{width} column specifier: e.g. \begin{tabular}{ l p{10cm} } will put column's content into 10cm-wide parbox, and the text will be properly broken to several lines, like in normal paragraph. You can also use tabular* environment to specify width for the entire table.
Latex will automatically adjust the width of a cell in a table. If you wish to have a table where each cell in a row has the same width, you would use the p option instead of l , c or r for left, centre or right alignment. \caption {Table with equal cell width.}
You can resize it using \resizebox{<width>}{<height>} from the graphics package. The column width is \columnwidth and you can select ! for the height to make it scale along with the width.
This can be easily done by using \begin{adjustbox}{width=1.2\textwidth,center=\textwidth} .. \end{adjustbox} instead of the keys used above. This values will make the table 120% of the text width but keep it centered to the text.
The tabularx
package gives you
X
, all X
columns will grow to fill up the total width.For your example:
\usepackage{tabularx}
% ...
\begin{document}
% ...
\begin{tabularx}{\textwidth}{|X|X|X|}
\hline
Input & Output& Action return \\
\hline
\hline
DNF & simulation & jsp\\
\hline
\end{tabularx}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With