It is easy to style table separator lines/rules with a command outside of the table environment.
Minimum Working Example:
\documentclass{article}
\usepackage{booktabs}
\usepackage{colortbl}
\begin{document}
\arrayrulecolor{blue}
\begin{tabular}{l}
\toprule
Header\\
\midrule
abc\\
def\\
\bottomrule
\end{tabular}
\end{document}
However, would it be possible to style rows or grids of the table outside of the table environment as well? For example: Place specifications with styles for grids and row background colors before the table environment to keep the table source code clean?
In fact I want to build some nice looking invoice table like this:
The reason why I want to keep the source code clean is simply the fact that I copy the table content out of an external calculation program (LibreOffice Calc
) into LaTeX, so I do not want to adjust all rows manually by hand afterwards. In best case the table source code does not contain any style specifications, only mandatory elements like &
and \\
at the end of the row (what I can insert in my calculation program already).
The mentioned output of my calculation program is preformatted for LaTeX and looks like that:
\toprule
\textbf{Position} & \textbf{Date} & \textbf{Work type} & \textbf{Duration} & \textbf{Hourly rate} & \textbf{TOTAL} \\
\midrule
1 & 05/04/2018 & Cleaning the balcony & \SI{4}{\hour} & \SI{10}{\euro\per\hour} & \SI{40}{\euro} \\
2 & 05/04/2019 & Mowing the meadow & \SI{7.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{75}{\euro} \\
3 & 05/04/2020 & Planting some flowers & \SI{5.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{55}{\euro} \\
4 & 05/04/2021 & Producing ice cream & \SI{10.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{105}{\euro} \\
5 & 05/04/2022 & Cleaning the television & \SI{5.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{55}{\euro} \\
6 & 05/04/2023 & Building a pond & \SI{9}{\hour} & \SI{10}{\euro\per\hour} & \SI{90}{\euro} \\
7 & 05/04/2024 & Feeding the fishes & \SI{8.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{85}{\euro} \\
8 & 05/04/2025 & Cutting the trees & \SI{7}{\hour} & \SI{10}{\euro\per\hour} & \SI{70}{\euro} \\
9 & 05/04/2026 & Watering the flowers & \SI{3}{\hour} & \SI{10}{\euro\per\hour} & \SI{30}{\euro} \\
\midrule
& & & Summary: & \SI{1000}{\euro} \\
\bottomrule
As you can see it would be nice to just copy-and-paste this block into LaTeX without inserting additional style specifications manually by hand.
Complete Minimum Working Example (MWE):
\documentclass{article}
\usepackage[english, ngerman]{babel}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[per=slash,locale=DE]{siunitx}
\sisetup{round-mode = places, round-precision = 2, round-integer-to-decimal}
\newunit{\euro}{EUR}
\begin{document}
\begin{tabularx}{1\textwidth}{c c p{5cm} r r r}
\toprule
\textbf{Position} & \textbf{Date} & \textbf{Work type} & \textbf{Duration} & \textbf{Hourly rate} & \textbf{TOTAL} \\
\midrule
1 & 05/04/2018 & Cleaning the balcony & \SI{4}{\hour} & \SI{10}{\euro\per\hour} & \SI{40}{\euro} \\
2 & 05/04/2019 & Mowing the meadow & \SI{7.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{75}{\euro} \\
3 & 05/04/2020 & Planting some flowers & \SI{5.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{55}{\euro} \\
4 & 05/04/2021 & Producing ice cream & \SI{10.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{105}{\euro} \\
5 & 05/04/2022 & Cleaning the television & \SI{5.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{55}{\euro} \\
6 & 05/04/2023 & Building a pond & \SI{9}{\hour} & \SI{10}{\euro\per\hour} & \SI{90}{\euro} \\
7 & 05/04/2024 & Feeding the fishes & \SI{8.5}{\hour} & \SI{10}{\euro\per\hour} & \SI{85}{\euro} \\
8 & 05/04/2025 & Cutting the trees & \SI{7}{\hour} & \SI{10}{\euro\per\hour} & \SI{70}{\euro} \\
9 & 05/04/2026 & Watering the flowers & \SI{3}{\hour} & \SI{10}{\euro\per\hour} & \SI{30}{\euro} \\
\midrule
& & & Summary: & \SI{1000}{\euro} \\
\bottomrule
\end{tabularx}
\end{document}