Graphics, Figures & TablesShort question on tabularx and tabular*

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Faust
Posts: 55
Joined: Thu Oct 29, 2009 12:45 pm

Short question on tabularx and tabular*

Post by Faust »

I've been using tabular* for a while to get tables that have fixed column sizes and have the desired with (usually textwidth). This works ALMOST perfectly: only flaw is that on the first column there is a different indent compared to the last comlumn; see attached snippet and you'll know what I mean.

I used this code:

Code: Select all

\usepackage{booktabs}

\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}} lrrrrrr}
%\toprule
\multicolumn{7}{c}{\textsc{Kosten}} \\
\toprule
{\bfseries Year} &    {\bfseries 1} &    {\bfseries 2} &    {\bfseries 3} &    {\bfseries 4} &    {\bfseries 5} & {\bfseries Total} \\
\midrule

    total &    113.5 &    107.2 &    136.5 &    188.0 &    191.0 &    736.2 \\


\bottomrule
\end{tabular*}  
snippet1.jpg
snippet1.jpg (92.59 KiB) Viewed 3678 times
So I wanted to fix this and switched to the tabularx package which does exactly what I want on the left and right but calculates variable column widths which is not what I want. Who has a solution?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Short question on tabularx and tabular*

Post by meho_r »

That code snippet you provided returns expected alignment: lrrrrrr. So, the code you provided isn't enough to reproduce the problem. Please, post a complete MWE.
Faust
Posts: 55
Joined: Thu Oct 29, 2009 12:45 pm

Short question on tabularx and tabular*

Post by Faust »

Ok, Ive attached a complete working example with identical tables produced with tabular, tabular*, tabularx and tabulary

what I want is a table of exactly the textwith (which works with tabular*), but the alignment is not as I like. Tabulary does what I want with alignment but ignores to make it the textwidth. tabularx makes it the textwidth with the right alignment but makes variable spaces in between rows which looks like crap. Run the attached code and you will see!

Code: Select all

\documentclass[10pt,a4paper,oneside]{report}
\usepackage{tabularx}
\usepackage{tabulary}


\usepackage{float}

\usepackage{booktabs}


%\leftwatermark{\put(-151,-742.9){\usebox{\logozonderadres}}}
%
%\rightwatermark{\put(-124,-742.9){\usebox{\logometadres}}}


%\leftwatermark{\put(-151,-742.9){\usebox{\logozonderadres}}}


%\leftwatermark{\put(-105,0){\usebox{\logozonderadres}}}
%\rightwatermark{\put(-60,0){\usebox{\logozonderadres}}}

%\input{logotex}
%\newcolumntype{R}{>{\raggedleft\arraybackslash}X}

\begin{document}




%\newpage


\begin{table}[H]
\begin{minipage}[t]{1\textwidth}
\vspace{0pt}
\begin{tabulary}{1\textwidth}{LRRRRRR}
%\toprule
\multicolumn{7}{c}{USING TABULARY} \\
\toprule
%\toprule
   Jaar        &       1 &       2 &       3 &       4 &       5 &     Totaal \\
\midrule
Reclame/drukwerk &      10.0 &       2.0 &       2.0 &       2.0 &       2.0 &      18.0 \\

Salaris\footnote{Voor F.V. Broens.} &      36.0 &      42.0 &      42.0 &      42.0 &      42.0 &     204.0 \\

Verblijfskosten\footnote{footnote bla.} &      10.0 &       5.0 &       5.0 &       5.0 &       5.0 &      30.0 \\

Tickets &       6.0 &       3.0 &       3.0 &       3.0 &       3.0 &      18.0 \\

Management &      20.0 &      20.0 &      20.0 &      20.0 &      20.0 &     100.0 \\

Verblijfskosten\footnote{Voor het management.} &      10.0 &      10.0 &       5.0 &       5.0 &       5.0 &      35.0 \\

Onvoorzien &      15.0 &      10.0 &      10.0 &      10.0 &      10.0 &      55.0 \\

Salaris werknemers &            &       3.0 &      15.0 &      55.0 &      55.0 &     128.0 \\

Flessen/certificering &       5.0 &       7.7 &      21.0 &      28.0 &      28.0 &      89.7 \\
\midrule
			Totaal &     112.0 &     102.7 &     123.0 &     170.0 &     170.0 &     677.7 \\
\bottomrule
\end{tabulary}  
\end{minipage}
\end{table}
			
			
\begin{table}[H]
\begin{minipage}[t]{1\textwidth}
\vspace{0pt}
\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}} lrrrrrr}
%\toprule
\multicolumn{7}{c}{\textsc{USING TABULAR*}} \\
\toprule
%\toprule
   Jaar        &       1 &       2 &       3 &       4 &       5 &     Totaal \\
\midrule
Reclame/drukwerk &      10.0 &       2.0 &       2.0 &       2.0 &       2.0 &      18.0 \\

Salaris\footnote{Voor F.V. Broens.} &      36.0 &      42.0 &      42.0 &      42.0 &      42.0 &     204.0 \\

Verblijfskosten\footnote{footnote bla.} &      10.0 &       5.0 &       5.0 &       5.0 &       5.0 &      30.0 \\

Tickets &       6.0 &       3.0 &       3.0 &       3.0 &       3.0 &      18.0 \\

Management &      20.0 &      20.0 &      20.0 &      20.0 &      20.0 &     100.0 \\

Verblijfskosten\footnote{Voor het management.} &      10.0 &      10.0 &       5.0 &       5.0 &       5.0 &      35.0 \\

Onvoorzien &      15.0 &      10.0 &      10.0 &      10.0 &      10.0 &      55.0 \\

Salaris werknemers &            &       3.0 &      15.0 &      55.0 &      55.0 &     128.0 \\

Flessen/certificering &       5.0 &       7.7 &      21.0 &      28.0 &      28.0 &      89.7 \\
\midrule
			Totaal &     112.0 &     102.7 &     123.0 &     170.0 &     170.0 &     677.7 \\
\bottomrule
\end{tabular*}  
\end{minipage}
\end{table}




\begin{table}[H]
\begin{minipage}[t]{1\textwidth}
\vspace{0pt}
\begin{tabularx}{1\textwidth}{lXrXrXrXrXrXrX}
%\toprule
\multicolumn{7}{c}{USING TABULARX} \\
\toprule
%\toprule
   Jaar        &       1 &       2 &       3 &       4 &       5 &     Totaal \\
\midrule
Reclame/drukwerk &      10.0 &       2.0 &       2.0 &       2.0 &       2.0 &      18.0 \\

Salaris\footnote{Voor F.V. Broens.} &      36.0 &      42.0 &      42.0 &      42.0 &      42.0 &     204.0 \\

Verblijfskosten\footnote{footnote bla.} &      10.0 &       5.0 &       5.0 &       5.0 &       5.0 &      30.0 \\

Tickets &       6.0 &       3.0 &       3.0 &       3.0 &       3.0 &      18.0 \\

Management &      20.0 &      20.0 &      20.0 &      20.0 &      20.0 &     100.0 \\

Verblijfskosten\footnote{Voor het management.} &      10.0 &      10.0 &       5.0 &       5.0 &       5.0 &      35.0 \\

Onvoorzien &      15.0 &      10.0 &      10.0 &      10.0 &      10.0 &      55.0 \\

Salaris werknemers &            &       3.0 &      15.0 &      55.0 &      55.0 &     128.0 \\

Flessen/certificering &       5.0 &       7.7 &      21.0 &      28.0 &      28.0 &      89.7 \\
\midrule
			Totaal &     112.0 &     102.7 &     123.0 &     170.0 &     170.0 &     677.7 \\
\bottomrule
\end{tabularx}  
\end{minipage}
\end{table}


\begin{table}[H]
\begin{minipage}[t]{1\textwidth}
\vspace{0pt}
\begin{tabular}{lrrrrrr}
%\toprule
\multicolumn{7}{c}{USING TABULAR} \\
\toprule
%\toprule
   Jaar        &       1 &       2 &       3 &       4 &       5 &     Totaal \\
\midrule
Reclame/drukwerk &      10.0 &       2.0 &       2.0 &       2.0 &       2.0 &      18.0 \\

Salaris\footnote{Voor F.V. Broens.} &      36.0 &      42.0 &      42.0 &      42.0 &      42.0 &     204.0 \\

Verblijfskosten\footnote{footnote bla.} &      10.0 &       5.0 &       5.0 &       5.0 &       5.0 &      30.0 \\

Tickets &       6.0 &       3.0 &       3.0 &       3.0 &       3.0 &      18.0 \\

Management &      20.0 &      20.0 &      20.0 &      20.0 &      20.0 &     100.0 \\

Verblijfskosten\footnote{Voor het management.} &      10.0 &      10.0 &       5.0 &       5.0 &       5.0 &      35.0 \\

Onvoorzien &      15.0 &      10.0 &      10.0 &      10.0 &      10.0 &      55.0 \\

Salaris werknemers &            &       3.0 &      15.0 &      55.0 &      55.0 &     128.0 \\

Flessen/certificering &       5.0 &       7.7 &      21.0 &      28.0 &      28.0 &      89.7 \\
\midrule
			Totaal &     112.0 &     102.7 &     123.0 &     170.0 &     170.0 &     677.7 \\
\bottomrule
\end{tabular}  
\end{minipage}
\end{table}



\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Short question on tabularx and tabular*

Post by localghost »

Don't use the extra fill space for the first column.

Code: Select all

\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}}rrrrrr}
% table contents
\end{tabular*}

Best regards
Thorsten
Faust
Posts: 55
Joined: Thu Oct 29, 2009 12:45 pm

Re: Short question on tabularx and tabular*

Post by Faust »

damn brilliant! THANKS!
Post Reply