Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

latex tabular width the same as the textwidth [closed]

Tags:

latex

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.

like image 959
Max_Salah Avatar asked May 19 '12 13:05

Max_Salah


People also ask

How do you fix the width of a table in LaTeX?

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.

How do I make table columns the same width in LaTeX?

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.}

How do you change the size of a tabular in LaTeX?

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.

How do I force a table to fit in LaTeX?

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.


1 Answers

The tabularx package gives you

  1. the total width as a first parameter, and
  2. a new column type 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}
like image 143
Ulrich Schwarz Avatar answered Oct 11 '22 20:10

Ulrich Schwarz