0

I'm writing an elsevier els-cas article and am trying to hatch some table cells for a table\tabular setting. It seemed to work fine until I used \resizebox and set the table size to \textwidth. The Tikz hatched cells don't seem to scale correctly. I looked at previous solutions such as hatching table cells fails when using positioning and Correctly scaling a tikzpicture but the solutions don't seem to suit the table environment I'm working with.

For the MWE I wasn't able to fit any hatch correctly in one cell, not to mention two. I'm looking for something like this (see attached picture).

The MWE:

\documentclass[a4paper]{cas-dc}

\usepackage{makecell} \usepackage{tikz} \usepackage{multirow}

\begin{document}

\begin{table}[] \resizebox{\textwidth}{!}{%

\begin{tabular}{c|ll|llc|cccc|} \multicolumn{1}{l|}{\multirow{2}{}{}} & \multicolumn{2}{c|}{\multirow{2}{}{Unit}} & \multicolumn{3}{c|}{Time} & \multicolumn{4}{c|}{Non-uniformity} \ \cline{4-10} \multicolumn{1}{l|}{} & \multicolumn{2}{c|}{} & \multicolumn{1}{c|}{1} & \multicolumn{1}{l|}{2} & 3 & \multicolumn{1}{c|}{1} & \multicolumn{1}{c|}{2} & \multicolumn{1}{c|}{3} & 4 \ \hline \multirow{3}{*}{\begin{tabular}[c]{@{}c@{}}Single-\ part\end{tabular}} & \multicolumn{2}{l|}{x} & \multicolumn{3}{l|}{} & \multicolumn{3}{c|}{} & \ \cline{2-10} & \multicolumn{2}{l|}{y} & \multicolumn{3}{l|}{} & \multicolumn{3}{c|}{} & \ \cline{2-10} & \multicolumn{2}{l|}{z} & \multicolumn{3}{l|}{} & \multicolumn{3}{c|}{} & \multicolumn{1}{l|}{} \ \hline \end{tabular}} \end{table}

\end{document}

Which looks like this: MWE But I hope to create this: Goal

JimV
  • 3

1 Answers1

1

If you actually want to resize a tabular with \resizebox a tabular with hatched cells, you may try {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{patterns}
\usepackage{lipsum} % for dummy text

\begin{document}

\sffamily

\lipsum[1]

\tikzset{mypattern/.style = {pattern=grid,pattern color=lightgray}}

\noindent \resizebox{\textwidth}{!}{\begin{NiceTabular}{ccccccccc|}[hvlines-except-borders] \Block{2-1}{} & \Block{2-1}{Unit} & \Block{1-3}{Time} & & & \Block{1-4}{Non-uniformity} &&&\ & & 1 & 2 & 3 & 1 & 2 & 3 & 4 \ \Block{3-1}{Single-\part} & x & \Block{1-3}{} & & & \Block{1-3}{} \ & y & \Block{1-3}{} & & & \Block{1-3}{} & & & \Block[tikz=mypattern]{}{} \ & z & \Block[tikz=mypattern]{1-3}{} & & & \Block[tikz=mypattern]{1-3}{} \ \Hline \end{NiceTabular}}

You need several compilations because nicematrix uses PGF/Tikz nodes.

Output of the first code

But it's probably better to use X columns (in the style of the X columns of {tabularx}).

\documentclass{article}
\usepackage{nicematrix,tikz}
\usetikzlibrary{patterns}
\usepackage{lipsum} % for dummy text

\begin{document}

\sffamily

\lipsum[1]

\tikzset{mypattern/.style = {pattern=grid,pattern color=lightgray}}

\noindent \begin{NiceTabular}{cc*{7}{X[c]}|}[hvlines-except-borders] \Block{2-1}{} & \Block{2-1}{Unit} & \Block{1-3}{Time} & & & \Block{1-4}{Non-uniformity} &&&\ & & 1 & 2 & 3 & 1 & 2 & 3 & 4 \ \Block{3-1}{Single-\part} & x & \Block{1-3}{} & & & \Block{1-3}{} \ & y & \Block{1-3}{} & & & \Block{1-3}{} & & & \Block[tikz=mypattern]{}{} \ & z & \Block[tikz=mypattern]{1-3}{} & & & \Block[tikz=mypattern]{1-3}{} \ \Hline \end{NiceTabular}

\end{document}

Output of the second code

F. Pantigny
  • 40,250