[Tugindia] Tabular environment in Latex

Radhakrishnan CV cvr at river-valley.org
Wed Aug 27 14:57:17 CEST 2003


>>>>> "JAYESH" == JAYESH KUMAR <jayesh at igidr.ac.in> writes:

    JAYESH> Dear All, I am trying to make a table, in which I want the
    JAYESH> {\linesize} to determine the width of columns
    JAYESH> automatically depending on the number of columns in the
    JAYESH> table.

    JAYESH> For example:

    JAYESH> I want to make a table of 5 columns, where paper size is
    JAYESH> A4. I want the 1st and 3rd column to be of p{3cm} each,
    JAYESH> and the rest 3columns should be equally distributed in
    JAYESH> width size.

    JAYESH> So that I don't need to put column width for all the
    JAYESH> columns and I should have flexibility to change one if I
    JAYESH> need to.

    JAYESH> I am sure Latex must have some way or the other to do the
    JAYESH> task. But I am not able to figure it out. Can someone help
    JAYESH> me???

Here is a quick and dirty trick:

\newdimen\bl
\def\recomputelength#1#2{%
  \setlength\bl\textwidth
  \addtolength{\bl}{-#1}
  \addtolength{\bl}{-#2\tabcolsep}
  \addtolength{\bl}{-#2\tabcolsep}
  }

\recomputelength{6cm}{6} % 6cm = total width of columns to
                         %       width is explicitly 
                         %       provided
                         % 6   = total number of columns  
\parindent 0pt

\hrule % to compare the tabular with textwidth 

\bigskip

\begin{tabular}{|p{3cm}%      first col - width provided
                |p{.25\bl}%   second col 25% of balance length
                |p{3cm}%      third col - width provided
                |p{.25\bl}%   fourth col 25% of balance length
                |p{.25\bl}%   fifth -do 
                |p{.25\bl}|}% sixth -do-
\hline
\hrulefill &
\hrulefill &
\hrulefill &
\hrulefill &
\hrulefill &
\hrulefill \\
\hline
\end{tabular}


Radhakrishnan


More information about the tugindia mailing list