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:
- No white colored spaces above and below the lines
- I would like to adjust the spacing between the lines generally
- The table shall have exactly the width of my text
- I want to adjust the width of all columns by my self specifying in percent
- I want in some cases have the first column colored differently
- I want the text in my head row to be white
- I need to use footnotes in the table. It doesn't matter if they are explained below the table or at the page bottom.
- I want to change the horizontal alignment of the cells with numbers in it to right align.
- 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}
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, foraboverulesep
. 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 frommakecell
. 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 3X
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 (otthreeparttablex
for long tables). For usual footnote, you have thetablefootnote
package.Point 8. To have numbers right-aligned, you can add
>{\raggedleft}
to the column specifier, or choose theS
column type (loadsiunitx
).