0
\documentclass[12pt]{article}

\usepackage[
    a4paper,
    margin = 5mm,
    landscape,
    %showframe,
    ]
    {geometry}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}

\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}

\usepackage[table]{xcolor}    % loads also colortbl
\definecolor{myTableColor}{gray}{0.80}

\usepackage[sfdefault]{cabin}

\begin{document}

\noindent
\setlength{\arrayrulewidth}{1pt}
\begin{tabularx}{\textwidth}{lc|l|X|X|X|X}
\toprule
\rowcolor{myTableColor}
\multicolumn{2}{l}{\textbf{Text}} & Text & Text & Text & Text & Text\\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
%\cmidrule{3-7}
\cline{3-7}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\midrule
\multicolumn{2}{l|}{Text} & & & & & \\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
\cmidrule{3-7}
%\cline{3-7}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\bottomrule
\end{tabularx}

% \multirow{-2}{*}{A} is taken from user Gonzalo Medina
% https://tex.stackexchange.com/questions/21155

\end{document}

enter image description here


  • I have multirow and cellcolor.
  • I want to use \cmidrulefrom booktabs.
  • I get a weird while line.
  • \cline works fine.
  • I also tried \cmidrule[0pt].
  • Also, the line width of \cmidrule and \midrule seems to be different.
4
  • Is there any particular reason why you do not want to use \cline?
    – Bernard
    Apr 22, 2017 at 0:03
  • @Bernard I wanted to use the booktabs rules (mid/top/bottom). The cline has a different width. But maybe I just should google how to change the line width :). Apr 22, 2017 at 0:09
  • 1
    The makecell package defines the \xhline and \xcline commands, and boldline, from the shipunov bundle have such commands, \hlineB and \clineB, with a slightly different syntax.
    – Bernard
    Apr 22, 2017 at 0:20
  • @Bernard Thanks. I don't have much experience with tables and I will look into it. Apr 22, 2017 at 0:23

2 Answers 2

2

This code does more or less what you want with makecell and a \Xcline{3-7}{0.05em}: the value of 0.05em is the default thickness of \midrule (\lightrulewidth). As to \cmidrule, the default is 0.03em.

\documentclass[12pt]{article}

\usepackage[
    a4paper,
    margin = 5mm,
    landscape,
    %showframe,
    ]
    {geometry}

\usepackage{tabularx}
\usepackage{booktabs, makecell}
\usepackage{multirow}

\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}

\usepackage[table]{xcolor} % loads also colortbl
\definecolor{myTableColor}{gray}{0.80}

\usepackage[sfdefault]{cabin}

\begin{document}

\noindent
\setlength{\arrayrulewidth}{1pt}
\begin{tabularx}{\textwidth}{lc|l|X|X|X|X}
\toprule
\rowcolor{myTableColor}
\multicolumn{2}{l}{\textbf{Text}} & Text & Text & Text & Text & Text\\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
\Xcline{3-7}{0.05em}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\midrule
\multicolumn{2}{l|}{Text} & & & & & \\
\midrule
Text & \cellcolor{myTableColor} & & & & & \\
\Xcline{3-7}{0.05em}
Text & \cellcolor{myTableColor}\multirow{-2}{*}{A} & & & & & \\
\bottomrule
\end{tabularx}

% \multirow{-2}{*}{A} is taken from user Gonzalo Medina
% https://tex.stackexchange.com/questions/21155

\end{document} 

enter image description here

3
  • Never used makecell before -- thanks! Apr 22, 2017 at 1:06
  • 1
    What's funny is these thick rule commands are only a by-product of makecell: it mainly aims at allowing line breaks and a common formatting of cells like column heads.
    – Bernard
    Apr 22, 2017 at 9:13
  • I read (roughly) the docu yesterday in bed -- seems pretty useful. Apr 22, 2017 at 9:22
1

With {NiceTabular} of nicematrix, you can use directly \midrule and \cmidrule of booktabs with the expected output.

\documentclass[12pt]{article}
\usepackage{xcolor} 
\usepackage[a4paper,margin = 5mm,landscape]{geometry}

\usepackage{booktabs}
\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}

\usepackage{nicematrix}


\definecolor{myTableColor}{gray}{0.80}

\usepackage[sfdefault]{cabin}

\begin{document}

\noindent
\setlength{\arrayrulewidth}{1pt}
\begin{NiceTabularX}{\textwidth}{lc|l|X|X|X|X}
\toprule
\RowStyle[rowcolor=myTableColor]{}
\Block[l]{1-2}{\textbf{Text}} & Text & Text & Text & Text & Text \\
\midrule
Text & \Block[fill=myTableColor]{2-1}{A} & & & & & \\
\cmidrule{3-7}
Text \\
\midrule
Text \\
\midrule
Text & \Block[fill=myTableColor]{2-1}{A} & & & & & \\
\cmidrule{3-7}
Text \\
\bottomrule
\end{NiceTabularX}
    
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .