[Tex/LaTex] Adjust table widths, spacing and color

horizontal alignmentrowcolorspacingtables

I have a question regarding tables in Latex. I tried to find a solution now for two hours, but couldn't fix all my problems in one code. So I found single solutions for everything, but couldn't bring them together.

I added some code and a picture to explain the table I want to have in the end. Unfortunately there are some points I don't like and hope someone can help me. I would like to have:

  1. No white colored spaces above and below the lines
  2. I would like to adjust the spacing between the lines generally
  3. The table shall have exactly the width of my text
  4. I want to adjust the width of all columns by my self specifying in percent
  5. I want in some cases have the first column colored differently
  6. I want the text in my head row to be white
  7. I need to use footnotes in the table. It doesn't matter if they are explained below the table or at the page bottom.
  8. I want to change the horizontal alignment of the cells with numbers in it to right align.
  9. I'm open to the package to use, so if needed feel free to propose another one 🙂

Thank you very much for your help.

\documentclass{scrbook}

\usepackage{lipsum}

\usepackage{tabularx} 
\usepackage{booktabs}

\usepackage{colortbl}
\definecolor{Gray}{rgb}{0.80784, 0.86667, 0.90196} %dunkelblau
\definecolor{Lightgray}{rgb}{0.9176, 0.95, 0.95686} %hellblau
\definecolor{Akzent}{rgb}{0.6627, 0.63529, 0.55294} %akzentfarbe

\begin{document}

\lipsum[2]
\begin{table}
\begin{center}
\begin{tabularx}{\textwidth}{p{.15\linewidth} p{.1\linewidth} p{.2\linewidth} p{.2\linewidth} X}
    \toprule
    \rowcolor{Akzent}
    Category & Size & Maximum Takeoff Weight (MTOW) (kg) & Normal Operating Altitude (ft) & Airspeed (m/s)\\
    \midrule
    \rowcolor{Gray}
    Group 1 & Small & 0 - 20 & < 1,200 AGL & < 100\\
    \rowcolor{Lightgray}
    Group 2 & Medium & 21 - 55 & < 3500 & < 250\footnote{Explanation}\\
    \bottomrule
\end{tabularx}
\caption{Table}
\end{center}
\end{table}

\end{document}

enter image description here

Best Answer

Here is something that looks nicer, though far from perfect. For point 1, it's due to the padding that booktabs adds above and/or below its rules. So I had to suppress this padding, and replace it with \extrarowsep, for \belowrulesep and with a rule of the same thickness as below, and same colour as the row colour, for aboverulesep. To ease doing so, I defined a \colourpadding command, with one argument, the colour one wishes.

There might have been a simpler solution with the \makegapedcells command from makecell. Unfortunately, it appears not to be compatible with colouring tables.

Point 2: There are several ways to do that. The simplest is changing the value of arraystretch. It has the inconvenience that for bib values, the contents is no more centred in its cell. If necessary, you can use \arraystretch=some length, which adds a length at the top of cells in each row. Two last solutions: makecell has two commands: \setcellgapes{some length} and \makegapedcells}, which adds a fixed length at the top and bottom of all cells in a table. It does not work here. Last solution: cellspace defines minimal distances between the top of a cell and the line above (or the bottom of the row above), and between the bottom of a cell and the line below.

Point 3. It's done with tabularx. I preferred to use 3 X columns, and slightly change the first two columns widths.

Point 4: I don't see what you want exactly.

Point 5: I think you would have to colour differently each cell of the first column, via \cellcolor.

Point 6 is done.

Point 7: Footnotes can be put at the bottom of the table with the threeparttable package (ot threeparttablex for long tables). For usual footnote, you have the tablefootnote package.

Point 8. To have numbers right-aligned, you can add >{\raggedleft} to the column specifier, or choose the S column type (load siunitx).

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e, eqparbox}
\newcolumntype{M}[1]{>{\RaggedRight}m{#1} <{\hspace*{-1pt}}}

\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}

\usepackage[table]{xcolor}
\definecolor{Gray}{rgb}{0.80784, 0.86667, 0.90196} %dunkelblau
\definecolor{Lightgray}{rgb}{0.9176, 0.95, 0.95686} %hellblau
\definecolor{Akzent}{rgb}{0.6627, 0.63529, 0.55294} %akzentfarbe
\newcommand{\whitehead}{\bfseries\color{white}}

\newcommand\colourpadding[1]{\addlinespace[-1pt]\arrayrulecolor{#1}\midrule[6pt]\arrayrulecolor{black}}

\begin{document}

\lipsum[2]
\begin{table}
\centering
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\setlength\doublerulesep{0pt}
\setlength\extrarowheight{5pt}
\begin{tabularx}{\textwidth}{M{.12 \linewidth}M{.08\linewidth}*{3}{X}} \toprule
    \rowcolor{Akzent}
 \whitehead Category & \whitehead Size &\whitehead Maximum Takeoff Weight (MTOW) (kg) &\whitehead Normal Operating Altitude (ft) &\whitehead Airspeed (m/s)\\
    \colourpadding{Akzent}
        \midrule
        \rowcolor{Gray}
        Group 1 & Small & 0 – 20 & \eqmakebox[A][l]{< 1,200 AGL} & < 100\\
    \colourpadding{Gray}
        \rowcolor{Lightgray}
        Group 2 & Medium & 21 – 55 & \eqmakebox[A][l]{< 3500} & < 250\rlap{\footnote{Explanation}}\\
\colourpadding{Lightgray}
    \bottomrule
\end{tabularx}
\caption{Table}
\end{table}

\end{document} 

enter image description here

Related Question