Approximate excel spreadsheet
NB! Do not use tabu
. It is an outdated and depreciated package.
Using cals
Here is a possible solution using cals. In this second version, I have updated the code with lighter rules (0.4pt). The colours are set according to your MWE. I removed the background page colour and colourised the tabular light gray:
\documentclass[11pt, a4paper, twoside]{report} % If you use standard margins, you need
% footnotesize for table and enlarge the page with two
% baselineskips to have room for the table
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{xcolor, cals}
\renewcommand{\sfdefault}{uop} % Optima as sans serif font
\renewcommand{\rmdefault}{\sfdefault} % Whole document in sans serif
\usepackage{pdflscape} % It is necessary to set the table in landscape
% An alternative is to rotate the table
\let\nc=\nullcell % Shortcuts
\let\sc=\spancontent
\definecolor{maincolorLight}{HTML}{838fbc}
\definecolor{darkGray}{HTML}{e6e6e6}
\definecolor{lightGray}{HTML}{f2f2f2}
\begin{document}
%\pagecolor{gray!10} % Set page background light gray
\begin{landscape}
\footnotesize % If not, the tabular is to wide for the standard margins
\enlargethispage{3\baselineskip} % If not, the tabular is to high for the standard margins
\noindent\begin{calstable}
% Defining 9 column relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth/90 *3)\relax}
{\dimexpr(\columnwidth/90 *3)\relax}
{\dimexpr(\columnwidth/90 *13)\relax}
{\dimexpr(\columnwidth/90 *13)\relax}
{\dimexpr(\columnwidth/90 *13)\relax}
{\dimexpr(\columnwidth/90 *13)\relax}
{\dimexpr(\columnwidth/90 *12)\relax}
{\dimexpr(\columnwidth/90 *10)\relax}
{\dimexpr(\columnwidth/90 *10)\relax}
}
% The 9 columns have to sum up to 90 to fill the text area
% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt} % Outside frame rules, decrease if you find the rule too heavy
\def\cals@framecs@width{0.4pt}
\def\cals@cs@width{0.4pt} % Inside rules, decrease if you find the rule too heavy
\def\cals@rs@width{0.4pt}
\def\cals@bodyrs@width{0.4pt} % The rule between title and body
\cals@setpadding{Ag} % Default value
\cals@setcellprevdepth{Al} % Default value
\def\cals@bgcolor{} % Initiate cals@bgcolor to empty
\def\dgray{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{darkGray!80!black}
\else \def\cals@bgcolor{} \fi}
\def\gray{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{darkGray}
\else \def\cals@bgcolor{} \fi}
\def\lgray{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{lightGray}
\else \def\cals@bgcolor{} \fi}
\def\white{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{white}
\else \def\cals@bgcolor{} \fi}
\def\blue{\ifx\cals@bgcolor\empty % Colour switch (on-off)
\def\cals@bgcolor{maincolorLight!50}
\else \def\cals@bgcolor{} \fi}
\def\bb{\ifx\cals@borderB\relax % Bottom border switch (off-on)
\def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}
\def\lb{\ifx\cals@borderL\relax % Left border switch (off-on)
\def\cals@borderL{0pt}
\else \let\cals@borderL\relax\fi}
\def\rb{\ifx\cals@borderR\relax % Right border switch (off-on)
\def\cals@borderR{0pt}
\else \let\cals@borderR\relax\fi}
\def\rp{\ifdim\cals@paddingR=0.0pt\relax % Left padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingR}{0pt}\fi}
% R1 Heading
\thead{
\brow
\dgray\alignC\cell{} % Switched on dark gray. Works until it is turned off.
\cell{A}
\cell{B}
\cell{C}
\cell{D}
\cell{E}
\cell{F}
\cell{G}
\cell{H}\dgray % Switch off dark gray at the end of the row.
\erow
}
% R2 Body
\brow
\dgray\cell{\vfill1}\dgray
\lgray\bb\nc{ltb}
\nc{tb}
\nc{tb}
\nc{tb}
\nc{tb}
\nc{tb}
\nc{tb}
\nc{rtb}\sc{\rule{2pt}{0pt}\vfil\Large\bfseries Skatteberegning for personer med personinntekt over kr 565\,400}\bb\rb\lgray
\erow
% R3 Body
\brow
\rb\dgray\cell{2}\dgray\rb
\lgray\bb\cell{}
\bb\cell{}
\cell{}\bb
\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R4 Body
\brow
\bb\dgray\cell{3}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Personinntekt}\gray
\white\cell{}\white\rb\bb
\lgray\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R5 Body
\brow
\bb\dgray\alignC\cell{4}\dgray\bb
\lgray\cell{}\rb\lgray
\gray\bb\rb\alignL\cell{\bfseries Samlet fradrag:}\gray
\white\cell{}\white\rb\bb
\lgray\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R6 Body
\brow
\bb\dgray\alignC\cell{5}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Alminnelig inntekt:}\gray
\blue\cell{}\blue\bb\rb
\lgray\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R7 Body
\brow
\bb\dgray\alignC\cell{6}\dgray\rb\bb
\lgray\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R8 Body
\brow
\bb\dgray\cell{7}\dgray\bb
\lgray\rb\cell{}
\bb\cell{}
\cell{}
\cell{}
\cell{}\bb
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R9 Body
\brow
\bb\dgray\cell{8}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\nc{ltb}
\nc{rtb}\alignL\sc{}
\alignC\cell{\bfseries Prosentsats}
\cell{\bfseries Beløp}\rb\bb\gray
\lgray\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R10 Body
\brow
\bb\dgray\alignC\cell{9}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\nc{ltb}
\nc{rtb}\alignL\sc{\bfseries Skatt av alminnelig inntekt:}
\alignC\cell{\bfseries 25 \%}\gray
\blue\cell{}\blue\bb\rb
\lgray\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R11 Body
\brow
\bb\dgray\cell{10}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\nc{ltb}
\nc{rtb}\alignL\sc{\bfseries Trygdeavgift:}
\alignC\cell{\bfseries 8,2 \%}\gray
\blue\cell{}\blue\bb\rb
\lgray\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R12 Body
\brow
\bb\dgray\cell{11}\dgray\bb
\lgray\rb\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R13 Body
\brow
\bb\dgray\cell{12}\dgray\bb
\lgray\rb\cell{}
\bb\alignL\cell{\bfseries Trinnskatt}
\cell{}
\cell{}
\cell{}
\cell{}\bb
\cell{}
\rb\cell{}\lgray
\erow
% R5 Body
\brow
\bb\dgray\alignC\cell{13}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\cell{}
\alignC\cell{\bfseries Prosentsats}
\cell{\bfseries Fra}
\cell{\bfseries Til}
\cell{\bfseries Skatt på trinn}\bb\rb\gray
\lgray\cell{}
\rb\cell{}\lgray
\erow
% R5 Body
\brow
\bb\dgray\alignC\cell{14}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Trinn 1:}
\alignC\cell{0,44 \%}
\alignL\cell{kr \hfill 159\,800,00}
\alignL\cell{kr \hfill 224\,900,00}\gray
\blue\cell{kr \hfill 286,44}\blue\bb\rb
\lgray\cell{}
\rb\cell{}\lgray
\erow
% R16 Body
\brow
\bb\dgray\alignC\cell{15}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Trinn 2:}
\alignC\cell{1,4 \%}
\alignL\cell{kr \hfill 224\,900,00}
\alignL\cell{kr \hfill 565\,400,00}\gray
\blue\cell{kr \hfill 5\,758,50}\blue\bb\rb
\lgray\cell{}
\rb\cell{}\lgray
\erow
% R17 Body
\brow
\bb\dgray\alignC\cell{16}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Trinn 3:}
\alignC\cell{10,7 \%}
\alignL\cell{kr \hfill 565\,400,00}
\alignL\cell{kr \hfill 909\,500,00}\gray
\blue\cell{}\blue\bb\rb
\lgray\cell{}
\rb\cell{}\lgray
\erow
% R18 Body
\brow
\bb\dgray\alignC\cell{17}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Trinn 4:}
\alignC\cell{13,7 \%}
\alignL\cell{kr \hfill 909\,500,00}
\alignL\cell{}\gray
\blue\cell{}\blue\bb\rb
\lgray\cell{}
\rb\cell{}\lgray
\erow
% R19 Body
\brow
\bb\dgray\alignC\cell{17}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Totalt:}
\alignC\cell{}
\alignL\cell{}
\alignL\cell{}\gray
\blue\cell{}\blue\bb\rb
\lgray\cell{}
\rb\cell{}\lgray
\erow
% R20 Body
\brow
\bb\dgray\cell{19}\dgray\bb
\lgray\rb\cell{}
\bb\cell{}
\cell{}\bb
\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R21 Body
\brow
\bb\dgray\cell{20}\dgray\bb
\lgray\cell{}\lgray
\gray\bb\alignL\cell{\bfseries Samlet skatt:}\gray
\blue\cell{}\bb\blue\rb
\lgray\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
% R22 Body
\brow
\bb\dgray\cell{21}\dgray
\lgray\rb\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\rb\cell{}\lgray
\erow
\makeatletter
\end{calstable}\par % \par needed to align the tabular
\end{landscape}
\end{document}
Using tabular
and friends
After several trials, I managed to build your tabular using standard tabular
, colortbl and hhline. Building the tabular is easy, but when you start colourising, the problems begin. When using colours in tables, cline
s and other rules are overwritten by the colour. This is documented in the colortbl-manual. You have to build the rules line by line, using hhline
’s syntax. When you remove part of a rule (to mimic cline
), hhline leaves thin white stripes instead (f.ex. the ligth gray background). This answer gives a solution by changing arraycolor
to the background colour. The syntax is bulky, in particular in complex tabular where you have to switch on and off arraycolour
multiple times.
I defined some shorthands to reduce clutter, but if you find cals’ syntax verbose, it is nothing compared to this. In my opinion, cals is better suited for this types of tabulars; well worth learning.
Below is the new MWE and the resulting tabular:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1cm]{geometry}
\usepackage{multicol, array, hhline}
\usepackage[table]{xcolor}
\definecolor{maincolorLight}{HTML}{838fbc}
\definecolor{darkGray}{HTML}{e6e6e6}
\definecolor{lightGray}{HTML}{f2f2f2}
\renewcommand{\arraystretch}{1.3}
\setlength{\extrarowheight}{1pt}
\newcommand{\tableTitle}{\multicolumn{5}{l|}{\cellcolor{lightGray}\large\bfseries Skatteberegning for personer med personinntekt over kr~565\,400\rule{0pt}{4ex}}}
\newcommand{\blvi}[1]{\multicolumn{6}{l|}{\cellcolor{lightGray}#1}}
\newcommand{\blv}[1]{\multicolumn{5}{l|}{\cellcolor{lightGray}#1}}
\newcommand{\bliii}{\multicolumn{3}{l|}{\cellcolor{lightGray}}}
\newcommand{\blii}{\multicolumn{2}{l|}{\cellcolor{lightGray}}}
\newcommand{\mig}[1]{\multicolumn{1}{l}{\cellcolor{lightGray}\textbf{#1}}}
\newcommand{\mcdg}[1]{\multicolumn{1}{c|}{\cellcolor{darkGray}#1}}
\newcommand{\midg}[1]{\multicolumn{1}{|c|}{\cellcolor{darkGray}#1}}
\newcommand{\dgr}{\cellcolor{darkGray}}
\newcommand{\lgr}{\cellcolor{lightGray}}
\begin{document}
\begin{table}[tbh]
\centering\small
\begin{tabular}{|l|l|l|l|r|r|r|}
\hhline{*{7}{-}}
\dgr{}
&\mcdg{A}
& \mcdg{B}
&\mcdg{C}
&\mcdg{D}
&\mcdg{E}
&\mcdg{F}
\\
\hhline{*{7}{-}}
\midg{1}
&\mig{}
&\tableTitle
\\
\hhline{|-|*{6}{>{\arrayrulecolor{lightGray}}-}|}\arrayrulecolor{black}
\midg{2}
&\blvi{}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}--|>{\arrayrulecolor{lightGray}}---|}
\arrayrulecolor{black}
\midg{3}
&\lgr
&\dgr\textbf{Personinntekt:}
&% white cell
&\bliii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}--|>{\arrayrulecolor{lightGray}}---|}
\arrayrulecolor{black}
\midg{4}
&\lgr
&\dgr\textbf{Samlet fradrag:}
&% white cell
&\bliii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}--|>{\arrayrulecolor{lightGray}}---|}
\arrayrulecolor{black}
\midg{5}
&\lgr
&\dgr\textbf{Alminnelig inntekt:}
&\cellcolor{maincolorLight}
&\bliii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}--|>{\arrayrulecolor{lightGray}}---|}
\arrayrulecolor{black}
\midg{6}
&\blvi{}
\\
\hhline{|-|*{6}{>{\arrayrulecolor{lightGray}}-}|}
\arrayrulecolor{black}
\midg{7}
&\blvi{}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}---|>{\arrayrulecolor{lightGray}}--|}
\arrayrulecolor{black}
\midg{8}
&\lgr
&\dgr
&\dgr\textbf{Prosentsats}
&\dgr\textbf{Beløp}
&\blii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}---|>{\arrayrulecolor{lightGray}}--|}
\arrayrulecolor{black}
\midg{9}
&\lgr
&\dgr\textbf{Skatt av alminnelig inntekt:}
&\mcdg{25\,\%}
&\cellcolor{maincolorLight}
&\blii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}---|>{\arrayrulecolor{lightGray}}--|}
\arrayrulecolor{black}
\midg{10}
&\lgr
&\dgr\textbf{Trygdeavgift:}
&\mcdg{8,5\,\%}
&\cellcolor{maincolorLight}
&\blii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}---|>{\arrayrulecolor{lightGray}}--|}
\arrayrulecolor{black}
\midg{11}
&\blvi{}
\\
\hhline{|-|*{6}{>{\arrayrulecolor{lightGray}}-}|}
\arrayrulecolor{black}
\midg{12}
&\mig{}
&\blv{\textbf{Trinnskatt}}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{13}
&\lgr
&\dgr
&\dgr{\textbf{Prosentsats}}
&\mcdg{\textbf{Fra}}
&\mcdg{\textbf{Til}}
&\dgr{\textbf{Skatt på trinn}}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{14}
&\lgr
&\dgr\textbf{Trinn 1:}
&\mcdg{0,44\,\%}
&\dgr{159\,800,00}
&\dgr{224\,900,00}
&\cellcolor{maincolorLight}\textbf{286,44}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{15}
&\lgr
&\dgr\textbf{Trinn 2:}
&\mcdg{1,7\,\%}
&\dgr{224\,900,00}
&\dgr{565\,400,00}
&\cellcolor{maincolorLight}\textbf{5788,50}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{16}
&\lgr
&\dgr\textbf{Trinn 3:}
&\mcdg{10,7\,\%}
&\dgr{565\,400,00}
&\dgr{909\,500,00}
&\cellcolor{maincolorLight}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{17}
&\lgr
&\dgr\textbf{Trinn 4:}
&\mcdg{13,7\,\%}
&\dgr{909\,500,00}
&\dgr
&\cellcolor{maincolorLight}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{18}
&\lgr
&\dgr\textbf{Totalt:}
&\dgr
&\dgr
&\dgr
&\cellcolor{maincolorLight}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}-----|}
\midg{19}
&\blvi{}
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}--|>{\arrayrulecolor{lightGray}}---|}
\arrayrulecolor{black}
\midg{20}
&\lgr
&\dgr\textbf{Samlet skatt:}
&\cellcolor{maincolorLight}
&\bliii
\\
\hhline{|-|>{\arrayrulecolor{lightGray}}->{\arrayrulecolor{black}}--|>{\arrayrulecolor{lightGray}}---|}
\arrayrulecolor{black}
\midg{21}
&\blvi{}
\\
\lasthline
\end{tabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
Worth to mention that the package pas-tableur
was made specifically to create a spreadsheet layouts, although probably not those with rich cell formattings (different grid thickness/backgrounds, etc.) as showed in the question (or maybe is perfect for this purpose, really I never used it).
\documentclass{article}
\usepackage{pas-tableur}
\begin{document}
\begin{tikzpicture}
\tableur[8]{A,B,C,D,E}
\celtxt[color=red]{D}{1}{=B3}
\celtxt*[r]{A}{3}{$\pi =$}
\celtxt*{B}{3}{3.14}
\selecCell{C}{5}
\celtxt[l]{C}{5}{28/12/2017}
\multiSelec{A-1}{C-2}
\celtxt[c]{B}{7}{Very long text that take more than one cell}
\end{tikzpicture}
\end{document}