Graphics, Figures & TablesColumn Properties in Table with full Width

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fboehlandt
Posts: 12
Joined: Mon Apr 15, 2013 6:28 pm

Column Properties in Table with full Width

Post by fboehlandt »

Hello everyone,

I am becoming increasingly frustrated with introducing tables into my document, in particular with the number of packages available (tabu, tabularx, tabulary, ...). My requirements are pretty straight-forward but I cannot get them aligned:
  1. Table full width of text.
  2. All columns equal width.
  3. Cell alignment left except first (cell alignment right).
  4. No padding for the cell left-/right-most position.
I have decided on tabularx and \newcolumntype (simply because it produced the least amount of errors), but I still can't get requirement 4 to work (I tried %{} but no luck).

Here is what I have:

Code: Select all

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

\begin{table}[H] \footnotesize
  \caption{Frequency distribution of returns}
  \centering
  \begin{tabularx}{\textwidth}{lRRRRRRRRR}%
    \toprule
          & m & $\bar \mu$  & $\bar \sigma^2$ & $\bar m_3$  & $\bar m_4$ & $\bar \chi_{JB}$   & $P_{\chi_{JB}}$ &  $\bar d_n$  & $\bar d_n$ \\
    \midrule
    ABC   & 38    & 1.28\% & 0.072 & 1.026 & 9.222 & 2572.5 & 89.5\% & 0.106 & 86.8\% \\
  \end{tabularx}
\end{table}
I'm happy to try other packages. The ones I tried don't seem particularly intuitive and are one of LaTeX's worst feature! Anyhow, any input on this is greatly appreciated.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Column Properties in Table with full Width

Post by cgnieder »

Hi fboehlandt,

Welcome to the LaTeX community!

You're nearly there. I took the liberty of completing your code snippet into a Infominimal working example (MWE) (if you don't know or are not sure what that is you should follow the link for future questions).
fboehlandt wrote:I am becoming increasingly frustrated with introducing tables into my document, in particular with the number of packages available (tabu, tabularx, tabulary, ...).
Tables are not one of LaTeX's strengths and often a source of frustration for many users so you are not alone :) The number of available packages often adds to the confusion but are a great resource once you get to know them and what they're capable of and what they can't do.
fboehlandt wrote:
  1. Table full width of text.
  2. All columns equal width.
  3. Cell alignment left except first (cell alignment right).
  4. No padding for the cell left-/right-most position.
  1. This is already solved by \begin{tabularx}{\textwidth}. I added \usepackage{showframe} to visualize this. You can safely remove it again.
  2. This is solved by using tabularx' X columns for all columns (you haven't used it for the first column).
  3. Your example contradicts your requirement 3. where you use exactly the opposite. I changed it accordingly but maybe that was wrong?
  4. This can be achieved by using array's @{<stuff>} syntax that can be used in the column specification and which inserts <stuff> between the columns where it is used and at the same time removes the space that's usually there. An empty @{} will suppress the space.
I also used array's *{<num>}{<spec>} which can be used as a shortcut to insert the same column type <num> times. Your column specification becomes {@{}R*{9}{X}@{}}.

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}

% visualize page dimensions:
\usepackage{showframe}

% table packages
\usepackage{array,booktabs,tabularx}
\begin{document}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}%

\begin{table}
  \caption{Frequency distribution of returns}
  \centering
  \begin{tabularx}{\textwidth}{@{}R*{9}{X}@{}}
    \toprule
          & m & $\bar \mu$  & $\bar \sigma^2$ & $\bar m_3$  & $\bar m_4$ & $\bar \chi_{JB}$   & $P_{\chi_{JB}}$ &  $\bar d_n$  & $\bar d_n$ \\
    \midrule
    ABC   & 38    & 1.28\% & 0.072 & 1.026 & 9.222 & 2572.5 & 89.5\% & 0.106 & 86.8\% \\
    % show that alignment is as demanded:
    r & l & l & l & l & l & l & l & l & l \\
    \bottomrule
  \end{tabularx}
\end{table}
\end{document}
Regards
site moderator & package author
fboehlandt
Posts: 12
Joined: Mon Apr 15, 2013 6:28 pm

Re: Column Properties in Table with full Width

Post by fboehlandt »

Hi Clemens,
thanks for your input. I guess full working examples do make life easier :) especially since it is easy to do in Latex. With your help I was able to implement all layout requirements.
Even though I am new to Latex, I love what you can do with this type-setting program (plus all freeware!). I'm never going to use word processing software for publications again. That is precisely why I was so surprised at the confusion surrounding tables and the compilation thereof. What is the best practice here? What is the latest 'unifying' package? I'm sure there is a thread regarding this, but I could not find it (I also didn't look very hard). It is in my opinion the only justification for using MS Word or similar...
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Column Properties in Table with full Width

Post by cgnieder »

fboehlandt wrote:I'm never going to use word processing software for publications again.
That's what I would like to say, too. But sometimes, due to requirements, collaborations, ... there sadly is no choice.
fboehlandt wrote:What is the latest 'unifying' package?
There is no unifying package, although tabu makes an attempt. Unfortunately its author said he is not going to fix any bugs but is rewriting the whole package (in order to make it more unifying, I guess) so I'm not sure if I want to recommend it.

I use array, booktabs and longtable a lot and so far had almost never to use any other package for my tables, but then I don't have any strict requirements or needs.

Regards
site moderator & package author
Post Reply