EDIT 20190807 At the end of the answer, I have included the code I recommend, an amalgamation of Zarko’s and my answer.
You may have a tabular
to use the whole linewidth
by calculating the width of p{}
-columns as fractions of the linewidth
. Just ensure that the total number of column widths accumulate to the linewidth
. You have to subtract the correct number of tabcolsep
s, which is two per column (total eight for four columns). If you have vertical rules, you also have to subtract the correct numbers of arrayrulewidth
s.
I have ‘improved’ the previous example. If you look at the definition of an A
-column, it now reads:
\newcolumntype{A}{>{\RaggedRight\arraybackslash}p{\dimexpr(1\textwidth)*25/100/2-1.5\tabcolsep\relax}}
- If you prefer centred or right aligned columns, you change
\RaggedRight
to \Centering
or \RaggedLeft
.
- If you need a tabular where the total width is less than the full
linewidth
, you change (1\linewidth)
to the correct fraction. For example, if you need a tabular 80 per cent of the linewidth
, you use (0.8\linewidth)
.
- The formula
25/100/2
is the relative width of the A
-column, here 25%. This number is meant to be set so that the total of the newcolumntype
is 100. Therefore, the B
-column use 75/100
. The last digit is the number of A
-or B
-columns.
- If you remove the left and right side bearings, (
@{}
), the number of tabcolsep
s to subtract will be two less than the total number of tabcolsept
s. If you have four columns, you have to subtract six, if you have six columns, you have so subtract ten, etc. The formula will be -(2\tabcolsep-(\tabcolsep/<no. col.type>))
. If you have three A
-columns, you have to subtract -(2\tabcolsep-(\tabcolsep/3))
.
- If you use vertical rules, you have to distribute the number of
arrayruleswidth
correctly, too. I leave it to you as an exercise to do that.
Above, I have assumed you will use equal number of each column types (ABAB, ABBA, ABBBAA etc.). In an automated calculation you have to take into consideration that the number of column types not necessarily will be the same number (you may have ABBAA, ABABA, etc.). So you will easily end up with a very complicated package. Probably it is better to use a calculator, or pen and paper, to fix the column width. Obviously, it is much faster than program it in LaTeX.
NB! I emphasise that tabularx
and tabulary
already do all the maths for you. However, have a look at section 4.3 in the tabularx
-manual.
Below I have enclosed code for a tabular with six columns:

\documentclass{article}
\usepackage{array, booktabs, ragged2e}
\newcolumntype{A}{>{\RaggedRight\arraybackslash}p{\dimexpr(1\textwidth)*25/100/3-(2\tabcolsep-(\tabcolsep/3))\relax}}
\newcolumntype{B}{>{\Centering\arraybackslash}p{\dimexpr(1\textwidth)*75/100/3-(2\tabcolsep-(\tabcolsep/3))\relax}}
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
\renewcommand*\ShowFrameLinethickness{.4pt}
\setlength{\tabcolsep}{2pt}
\begin{document}
{\centering
\begin{tabular}{@{}ABABBA@{}}
\toprule
A & B & A & B & A & B\\
\midrule
Short left alig\-ned column & Wide centered column, which has lots of text & Short left alig\-ned column & Wide centered column, which has lots of text & Wide centered column, which has lots of text & Short left alig\-ned column \\
\bottomrule
\end{tabular}%
}
\end{document}
Recommended example code
\documentclass{article}
\usepackage{booktabs, ragged2e}
\usepackage{tabularx}
\newcolumntype{D}{>{\small\RaggedRight\arraybackslash\hsize=0.4\hsize}X}
\newcolumntype{E}{>{\small\Centering\arraybackslash\hsize=1.6\hsize}X}
\setlength{\tabcolsep}{1.5pt}
\begin{document}
\noindent\begin{tabularx}{\linewidth}{@{}DEDEED@{}}
\toprule
D & E & D & E & E & D\\
\midrule
Short left alig\-ned column & Wide centered column, which has lots of text & Short left alig\-ned column & Wide centered column, which has lots of text & Wide centered column, which has lots of text & Short left alig\-ned column \\
\bottomrule
\end{tabularx}
\end{document}
\documentclass{article} \usepackage{tabularx} \begin{document} \begin{tabularx}{\linewidth}{*{2}{>{\hsize=0.4\hsize}X >{\hsize=1.6\hsize}X} } \hline xxx xxx & xxx xxx xxx xxx xxx xxx xxx xxx & xxx xxx & xxx xxx xxx xxx xxx xxx xxx xxx\\ \hline \end{tabularx} \end{document}
p{some-calculated-width}
.\linewidth
X
column type is nothing but ap
-type column for which LaTeX takes on the job of calculating the absolute width of the column should be, given information about the overall width of thetabularx
environment, the number ofX
-type columns, and the number and width of any other columns. SinceX
columns, likep
columns, are set up to allow automatic line breaking, it's not clear to me if there's enough information contained in the setup you've described to perform the required relative and absolute width calculations.