2

I have a simple table:

\begin{table}[h]
\begin{tabular}{|l|l|l|l|l|}
\hline
First entry & 2nd    & 3rd little longer & Forth & Fifth\\ \hline\hline
4.7\%  & 11.7\% & 2.5\%         & 80.5\%         & 0.7\%  \\ \hline
\end{tabular}
\caption{tabular}
\end{table}

I want it to use the whole page width by proportionally increasing the width of each column. So I do not want column widths to be spread equally; like this because the long line breaks:

\begin{table}[h]
\begin{tabu} to \textwidth {|*{5}{X[l]|}}
\hline
First entry & 2nd    & 3rd little longer & Forth & Fifth\\ \hline\hline
4.7\%  & 11.7\% & 2.5\%         & 80.5\%         & 0.7\%  \\ \hline
\end{tabu}
\caption{tabu}
\end{table}

Already tried tabulary but it only reduces the size of a table:

\begin{table}[h]
\begin{tabulary}{1.0\textwidth}{|l|l|l|l|l|}
\hline
First entry & 2nd    & 3rd little longer & Forth & Fifth\\ \hline\hline
4.7\%  & 11.7\% & 2.5\%         & 80.5\%         & 0.7\%  \\ \hline
\end{tabulary}
\caption{tabulary}
\end{table}

Here the output of a three samples (including a dummy text to see the page width):

enter image description here

  • Check out the tabularx package – John Kormylo Nov 12 '14 at 15:18
3

With tabularx:

\documentclass{article}
\usepackage{tabularx}

\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{|*{2}{X|}l|*{2}{X|}}
\hline
First entry & 2nd    & 3rd little longer & Forth & Fifth\\ \hline\hline
4.7\%  & 11.7\% & 2.5\%         & 80.5\%         & 0.7\%  \\ \hline
\end{tabularx}
\caption{tabularx}
\noindent X\hrulefill X % just for showing text width
\end{table}
\end{document}

The longest column (3) is typeset with an l column. The remaining columns are evenly distributed among the remaining width by using X columns.

enter image description here

  • what does *{2}{X|} mean? – Tiina Feb 7 '18 at 1:36
  • @Tiina it's just shorthand for "two copies of X|", that is X|X|. (In this case it doesn't actually save any space, but for many repeated columns it can make things much more compact.) – Paul Gessler Feb 7 '18 at 2:33
1

No-Package Method

You need to know the following things:

  • macro containing the width from left margin to right margin: \textwidth
  • macro containing value of cell separator width: \tabcolsep
  • how many cells: determined by you

Then you just need to do the math. This can be accomplished with \dimexpr:

Calculate Cell Width Based on Text Area Width \textwidth

cell width as percentage of text area width - 2(separator width)

\dimexpr .40\textwidth-2\tabcolsep

Example

Let's say that we have three columns. I will choose the paragraph column type p for line wrapping, which naturally makes you to set a maximum width.

  • 2 columns of 20% of text width = 40% of text width
  • 1 column of 60% of text width = 60% of text width

As long as the total of all column calculations = 100%, you're good to go!

\documentclass{article}
\usepackage{booktabs}% Used for visual illustration of tabular width
\begin{document}
Do not forget to remove the {\the\parindent} auto-indentation when testing widths. 

\noindent
\rule{\textwidth}{2mm}% proof that this table is maxed out
\bigbreak
\noindent% <== removes auto-indentation of article class for new paragraphs that do not follow a heading
\begin{tabular}{p{\dimexpr.20\linewidth-2\tabcolsep}p{\dimexpr.20\linewidth-2\tabcolsep}p{\dimexpr.60\linewidth-2\tabcolsep}}
\toprule
Dimension & Value+Unit & Description \\
\midrule
\textbackslash tabcolsep & \the\tabcolsep & The amount of space for each vertical cell border. \\
\textbackslash textwidth & \the\textwidth & The width from left margin to right margin. \\
\textbackslash parindtent & \the\parindent & The auto-indentation width. \\
\bottomrule
\end{tabular}
\end{document}

enter image description here


Notes

tabularx defines column type X to do essentially the same thing, except that it will automatically try to find the values for column type p{}.

http://mirror.easyname.at/ctan/macros/latex/required/tools/tabularx.pdf enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.