1

I have a table and I want to set the table width to a specific value, say 0.8\columnwidth. After the stretching, I want each column's width is proportional to its actual width in the original table. After searching the tex.stackexchange.com, I find the posts about using the tabularx or the tabulary package to stretch the table width, but none of them achieve what I desire.

The former achieves something like this: enter image description here The new column width are all the same, not proportional to its actual width.

The result the tabulary package produces is like this: enter image description here

There is no stretching effect in width.

The minimum working example is:

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{tabulary}

\begin{document}
\lipsum[1]
% the original table
\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|}
\hline
 first column     & second column  & third column                    \\
\hline
 short       & longer longer &  longest longest longest  \\
\hline
short  & longer longer & longest longest longest \\
\hline
\end{tabular}
\end{center}
\end{table}
%table after using tabularx package
\lipsum[2]
\begin{table}[h]
 \centering
  \begin{tabularx}{\columnwidth}{|X|X|X|}
  \hline
   first column     & second column  & third column                    \\
  \hline
 short       & longer longer &  longest longest longest  \\
\hline
short  & longer longer & longest longest longest \\
\hline
\end{tabularx}
\end{table}

 \lipsum[3]
  % table after using tabulary
 \begin{table}[h]
\begin{center}
\begin{tabulary}{\columnwidth}{|C|C|C|}
\hline
 first column     & second column  & third column                    \\
\hline
 short       & longer longer &  longest longest longest  \\
\hline
short  & longer longer & longest longest longest \\
\hline
\end{tabulary}
\end{center}
\end{table}
\end{document} 

Is there anything wrong with my way using these two packages? or is there any other way to achieve what I want? Thank you in advance!

  • The X column type can have a different width, with >{\hsize=x \hsize}X (the condition being the sum of the different x\hsizes is equal to the number of X columns. However, you have to calculate the coefficients by hand – Bernard Oct 29 '16 at 15:40
  • 1
    tabulary wraps over-wide columns but doesn't stretch columns (as doing so just makes the table harder to read, and I think it didn't occur to me that anyone would want that:-) however there is a patch in answer here tex.stackexchange.com/questions/87097/… – David Carlisle Oct 29 '16 at 15:41
  • @Bernard, but I do not know the exact width of the original column in the unit of \textwidth. So I can not calculate the coefficients manually. How to do it? Could you please post an answer? – jdhao Oct 30 '16 at 7:41
  • What is not clear is this: What is the actual width? X columns are typed in paragraph mode, which supposes their contents can spread over several lines. Will the cell contents always require only one line? Is there, say, a particular row which is representative of the widest contents of each column? – Bernard Oct 30 '16 at 12:34
  • @Bernard, suppose the widest cell in each column does not come from the same row but spreads only one line. Also the sum of width of these widest cells does not exceed the \textwidth. Under this condition, how to achieve the desired stretching? – jdhao Oct 30 '16 at 15:45

Your Answer

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

Browse other questions tagged or ask your own question.