0

When I trim the sides of tables using @{}, the \rowcolor hangs over the sides. I've fixed this with <{\kern-\tabcolsep} on the first and last column (according to this question). However, if \makecell is used in the first or last column, this method breaks down.

enter image description here

MWE:

\documentclass[11pt, a4paper]{scrartcl}

\usepackage[left=25mm,right=25mm,top=35mm,bottom=25mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage[flushleft]{threeparttable}
    \newcommand{\ltnote}[1]{\textsuperscript{\TPTtagStyle{#1}}}
\usepackage{siunitx}

\colorlet{tableheadcol}{gray!25}
\colorlet{rowcol}{gray!10}
\newcommand{\topline}{\arrayrulecolor{black}\specialrule{\heavyrulewidth}{\abovetopsep}{0pt}%
    \arrayrulecolor{tableheadcol}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{black}\rowcolor{tableheadcol}}
\newcommand{\midline}{\arrayrulecolor{tableheadcol}\specialrule{\aboverulesep}{0pt}{0pt}%
    \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{0pt}%
    \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{black}}
\newcommand{\bottomline}{\arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{-2pt}%
    \arrayrulecolor{black}\specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}


\begin{document}
    \begin{table}
    \centering\small
    \rowcolors{3}{rowcol}{white}
    \begin{threeparttable}
    \begin{tabular}{>{\kern-\tabcolsep}lS[table-format=4.0]c<{\kern-\tabcolsep}}
        \topline
        Kraftwerk & {\makecell{Leistung \\ in \si{\MW}\ltnote{b}}} & \makecell{geplante \\ Inbetriebnahme} \\
        \midline
        Berlin-Klingenberg & 300 & 2020 \\
        Berlin Lichtenberg & 260 & 2020 \\
        Burghausen & 850 & 2023 \\
        Dörpen & 170 & 2020 \\
        Gersteinwerk & 1300 & 2023 \\
        Herne 6 & 650 & 2022 \\
        Rheinhafen RDK 6s & 465 & 2021 \\
        Krefeld-Uerdingen & 900 & 2025 \\
        Leverkusen-Wiesdorf & 570 & 2022 \\
        Premnitz & 400 & 2023 \\
        \bottomline
    \end{tabular}
    \begin{tablenotes}
        \footnotesize
        \item[a] Kraftwerksprojekte ab einer elektrischen Bruttoleistung von \SI{100}{\MW}
        \item[b] elektrische Bruttoleistung
    \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}
fuj36840
  • 550
  • 1
    You could use a nested tabular as in Kraftwerk & {\makecell{Leistung \\ in \si{\MW}\ltnote{b}}} & \begin{tabular}{c}geplante \\ Inbetriebnahme\end{tabular} \\. – leandriis May 10 '20 at 15:06
  • does this introduce any additional vertical oder horizontal space? – fuj36840 May 10 '20 at 17:10
  • Kraftwerk & {\makecell{Leistung \\ in \si{\MW}\ltnote{b}}} & \begin{tabular}{@{}c<{\kern-\tabcolsep}}geplante \\ seems to do the job. – fuj36840 May 10 '20 at 17:18

3 Answers3

1

As @leandriis suggested in the comments, adding Kraftwerk & {\makecell{Leistung \\ in \si{\MW}\ltnote{b}}} & \begin{tabular}{@{}c<{\kern-\tabcolsep}}geplante \\ Inbetriebnahme\end{tabular} \\ for the headers solves the issue.

fuj36840
  • 550
1

You can do this table easily with nicematrix.

\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{nicematrix}
\usepackage{siunitx}

\begin{document}

\begin{NiceTabular}{@{}lS[table-format=4.0]c@{}} \CodeBefore \rowcolor{gray!25}{1} \rowcolors{2}{gray!10}{} \Body \toprule Kraftwerk & {\Block{}{Leistung \ in \unit{\MW}}} & \Block{}{geplante \ Inbetriebnahme} \ \midrule Berlin-Klingenberg & 300 & 2020 \ Berlin Lichtenberg & 260 & 2020 \ Burghausen & 850 & 2023 \ Dörpen & 170 & 2020 \ Gersteinwerk & 1300 & 2023 \ Herne 6 & 650 & 2022 \ Rheinhafen RDK 6s & 465 & 2021 \ Krefeld-Uerdingen & 900 & 2025 \ Leverkusen-Wiesdorf & 570 & 2022 \ Premnitz & 400 & 2023 \ \bottomrule \end{NiceTabular}

\end{document}

Output of the above code

F. Pantigny
  • 40,250
-1

The package cals can handle both rules and color

enter image description here

MWE

\documentclass{article} 
\usepackage{cals} 
\usepackage{xcolor} 

\begin{document} 

\begin{table*}[!htb] 
\begin{calstable}[c]
% Defining columns  
\colwidths{{1.5cm} 
            {2.25cm} 
            {1.75cm} 
            } 

% Set up the tabular 


\makeatletter 
\def\cals@framers@width{0.8pt}   % Outside frame rules, reduce if the rule is too heavy 
\def\cals@framecs@width{0pt} 
\def\cals@bodyrs@width{0.4pt}    % "midrule" - line between heading and body 
\cals@setpadding{Ag} 
\cals@setcellprevdepth{Al} 
\def\cals@cs@width{0pt}             % Inside rules, reduce if the rule is too heavy 
\def\cals@rs@width{0.6pt} 
\def\cals@bgcolor{} 

\def\gray{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour 
    \def\cals@bgcolor{gray!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} 

% R1B1 
\thead{% 
\brow 
    \gray\alignC\cell{1}\gray 
    \alignL\cell{2} 
    \gray\alignC\cell{3}\gray 
\erow 
}
%R2B2 
\brow 
    \gray\alignC\cell{\vfil one}\gray 
    \alignL\cell{\vfil two} 
    \gray\alignC\cell{\vfil three}\gray 
\erow 
%R3B3 
\brow 
    \gray\bb\alignC\cell{\vfil one}\bb\gray 
    \alignL\cell{\vfil two} 
    \gray\alignC\cell{\vfil three}\gray 
\erow 
%R4B4 
\brow 
    \gray\alignC\cell{\vfil one}\gray 
    \alignL\cell{\vfil two} 
    \gray\alignC\cell{\vfil three}\gray 
\erow 
%R4B4 
\brow 
    \gray\alignC\cell{\vfil un}\gray 
    \alignL\cell{\vfil deux} 
    \gray\alignC\cell{\vfil trois}\gray 
\erow 
\makeatletter 
\end{calstable}\par 
  \caption{caption} 
\end{table*} 
\end{document}
js bibra
  • 21,280