2

I am trying to make a latex table that looks like the picture. There should basically be 4 columns of rotated text under Header 1, one grey cell that that contains additional information. I am new to latex and have no idea how to make this table in booktabs style. enter image description here

\documentclass{article}
\newcommand*\turn{\rotatebox[origin=b]{90}}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, caption}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage[table,xcdraw]{xcolor}

\begin{document}

\begin{table}[] \centering \begin{tabular}{@{}llllll@{}} \toprule & \multicolumn{4}{c}{Header 1} & \ \cmidrule(lr){2-5} &\turn{Text1} &\turn{Text2} &\turn{Text3} & \turn{Text4} & \cellcolor{gray!25} \makecell[l]{Some line 1\ Some line 1\ Some line 1\ Some line 1\ Some line 1} \ Header 3 & & & & &Header 3\ \midrule

& & & & & \ & & & & & \ \bottomrule

\end{tabular} \end{table}

\end{document}

matais
  • 23

3 Answers3

1

enter image description here

MWE, which reproduce this (unusual) table (as you shown in question) is:

\documentclass{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{rotating}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[skip=1ex]{caption}

\begin{document} \begin{table}[htb] \centering \setlength\extrarowheight{2pt} \settowidth\rotheadsize{Text 4} \renewcommand\rotheadgape{} \begin{tabularx}{0.6\linewidth}{ l llll c@{,}X } \Xhline{1pt} & \multicolumn{4}{c}{Header 1} && \cellcolor{gray!25} \
\Xcline{2-5}{0.6pt} & \rothead{Text 1} & \rothead{Text 2} & \rothead{Text 3} & \rothead{Text 4} && \cellcolor{gray!25}% \multirow{-2.2}{=}{\noindent Some line 1 Some line 2 Some line 3} \ Header 3 & & & & && Header 3 \ \Xhline{0.6pt} A & & & & && 1 \ B & & & & && 2 \ \Xhline{1pt} \end{tabularx} \end{table} \end{document}

Addendum:

\documentclass{article}
\usepackage[table,xcdraw]{xcolor}
\usepackage{rotating}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcommand\mrrc[1]{\multirow{-2.4}{*}{\rothead{#1}}} % <---
\usepackage[skip=1ex]{caption}

\begin{document} \begin{table}[htb] \centering \setlength\extrarowheight{2pt} \settowidth\rotheadsize{Text 4} \renewcommand\rotheadgape{} \begin{tabularx}{0.6\linewidth}{ l llll c@{,}L } \Xhline{1pt} & \multicolumn{4}{c}{Header 1} && \cellcolor{gray!25} \
\Xcline{2-5}{0.6pt} & & & & && \cellcolor{gray!25} % <--- \small\linespread{0.84}\selectfont % <--- \multirow{-1.8}{=}{\noindent Some line 1 Some line 2 Some line 3} \[1ex] Header 3 & \mrrc{Text 1} % <--- rotated headers moved down & \mrrc{Text 2} & \mrrc{Text 3} & \mrrc{Text 4} && Header 3 \ \Xhline{0.6pt} A & & & & && 1 \ B & & & & && 2 \ \Xhline{1pt} \end{tabularx} \end{table} \end{document}

hopefully produce what you like to have:

enter image description here

Zarko
  • 296,517
1

Is it what you want to have?

\documentclass{article}
\newcommand*\turn{\rotatebox[origin=b]{90}}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, caption}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage[table,xcdraw]{xcolor}

\begin{document}

\begin{table}[] \centering \begin{tabular}{@{}llllll@{}} \toprule & \multicolumn{4}{c}{Header 1} & \ \cmidrule(lr){2-5} &\multirowcell{3.5}{\turn{Text1}} &\multirowcell{3.5}{\turn{Text2}} &\multirowcell{3.5}{\turn{Text3}} & \multirowcell{3.5}{\turn{Text4}} & \cellcolor{gray!25} \makecell{Some line 1\ Some line 1\ Some line 1\ Some line 1\ Some line 1} \ \addlinespace Header 3 & & & & &Header 3\ \midrule

& & & & & \ & & & & & \ \bottomrule \end{tabular} \end{table}

\end{document}

enter image description here

Bernard
  • 271,350
  • This is very close. I can take it from here as I almost got I wanted. Thanks a lot for your help, really appreciated. – matais Aug 27 '20 at 00:55
1

Here is a solution with {NiceTabular} of nicematrix.

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

\begin{document} \begin{table}[htb] \centering \setlength\extrarowheight{2pt} \begin{NiceTabular}{llllll} \CodeBefore \rectanglecolor{gray!20}{1-6}{2-6} \Body \toprule & \Block{1-4}{Header 1} &&& & \Block{2-1}{Some line 1\ Some line 2 \ Some line 3} \
\cmidrule(lr){2-5} \RowStyle{\rotate} & Text 1 & Text 2 & Text 3 & Text 4 \ Header 3 & & & & & Header 3 \ \midrule A & & & & & 1 \ B & & & & & 2 \ \bottomrule \end{NiceTabular} \end{table} \end{document}

  • This solution uses \booktabs (nicematrix is compatible with booktabs). Hence, it's easy to use shorten the \cmidrule with \cmidrule(rl) (there is no need of a dummy column).

  • The command \Block of nicematrix put its content at the mathematical center of the merge cells. There is no need to adjust manually as in \multirow.

  • The command \rowstyle applies formatting commands to all the cells of the row.

  • In nicematrix, the colored panels are drawn before all the rules (the output is better in the PDF viewers: the rules won't seem to disappear at some levels of zoom in some PDF viewers as Adobe Reader).

Ouput of the above code

F. Pantigny
  • 40,250