3

I try to make the next table with this hatching, dashed lines of cells and curly braces in Latex: enter image description here I have seen a lot of different examples on this website: Set table background hatched and shaded using tikz (hatching), Tables with colored cells and dashed lines (dashed lines of cells), How to mix coloring and hatching in the same cell in a tabular environment? (hatching+coloring).

But I haven't find hatching cells with both type of hatching (north east + north west) and whole combinations of features, which is needed in my example.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}         
\usepackage[english, russian]{babel}
\usepackage{amssymb,amsmath}
\usepackage{amsthm}
\usepackage{colortbl}
\usepackage{arydshln}
\usepackage{hhline}
\usepackage{multirow,bigdelim}
\usepackage{graphicx}
\usepackage[margin=2cm]{geometry} % just for the example 
\usepackage{fourier} 
\usepackage[table]{xcolor} 
\usepackage{array}
\usepackage{tabularx}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{calc,shadings,patterns}

\graphicspath{{pictures/}}

\makeatletter
\tikzset{%
  remember picture with id/.style={%
    remember picture,
    overlay,
    save picture id=#1,
  },
  save picture id/.code={%
    \edef\pgf@temp{#1}%
    \immediate\write\pgfutil@auxout{%
      \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
  },
  if picture id/.code args={#1#2#3}{%
    \@ifundefined{save@pt@#1}{%
      \pgfkeysalso{#3}%
    }{
      \pgfkeysalso{#2}%
    }
  }
}

\def\savepointas#1#2{%
  \expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

\def\tmk@labeldef#1,#2\@nil{%
  \def\tmk@label{#1}%
  \def\tmk@def{#2}%
}

\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
  \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
  \pgfsys@getposition{\pgfpictureid}\save@this@pic%
  \pgf@process{\pgfpointorigin\save@this@pic}%
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  \pgf@process{\pgfpointorigin\save@orig@pic}%
  \advance\pgf@x by -\pgf@xa
  \advance\pgf@y by -\pgf@ya
  }%
}
\newcommand\tikzmark[2][]{%
\tikz[remember picture with id=#2] {#1;}}
\makeatother
% end of Andrew's code

\newcommand\HatchedCell[4][0pt]{%
  \begin{tikzpicture}[overlay,remember picture]%
    \fill[#4] ( $ (pic cs:#2) + (0,1.9ex) $ ) rectangle ( $ (pic cs:#3) + (0pt,-#1*\baselineskip-.8ex) $ );
  \end{tikzpicture}%
}%

\newcommand\HatchedCellw[4][0pt]{%
  \begin{tikzpicture}[overlay,remember picture]%
    \fill[#4] ( $ (pic cs:#2) + (0,1.9ex) $ ) rectangle ( $ (pic cs:#3) + (0pt,-#1*\baselineskip-.8ex) $ );
  \end{tikzpicture}%

}%

\begin{document}


\HatchedCell{start3}{end3}{%
  pattern color=black!70,pattern=north east lines}

\HatchedCellw{start4}{end4}{%
  pattern color=black!70,pattern=north west lines}

\begin{tabular}[t]{|l|c|c|c|c|c|c|c|c|c|}
\cdashline{5-5} \hhline{----~----}
& $1$ & $2$ & $3$ & \hspace{0.4in} & $a_i$ & $a_i+1$ & $a_i+2$ & \hspace{0.4in} & $B$\\
\cdashline{5-5} \hhline{----~----}
\ldelim\{{5}{1mm}[$k<l_i$]  $1$ & & & & & & & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start4}}c!{\vrule\tikzmark{end4}}}{} &\multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start4}}c!{\vrule\tikzmark{end4}}}{} \rdelim\}{9}{1mm}[$k<j-a_i$]\\
\cdashline{5-5} \hhline{----~----}
$2$ & $\infty$ & & & & & & & & $\infty$ \\
\cdashline{5-5} \hhline{----~----}
$3$ & $\infty$ & $\infty$ & & & & & &\\
\cdashline{5-5} \hhline{----~----}
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{$\infty$} & \multicolumn{1}{c:}{$\infty$} & \multicolumn{1}{c:}{$\infty$} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\cdashline{5-5} \hhline{----~----}
$l_i-1$ & $\infty$ & $\infty$ & $\infty$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start4}}c!{\vrule\tikzmark{end4}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start4}}c!{\vrule\tikzmark{end4}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start4}}c!{\vrule\tikzmark{end4}}}{} & & $\infty$ \\
\cdashline{5-5} \hhline{----~----}
$l_i$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start4}}c!{\vrule\tikzmark{end4}}}{}  & & & & $\infty$ \\
\cdashline{5-5} \hhline{----~----}
$l_i+1$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & & & & &\\
\cdashline{5-5} \hhline{----~----}
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\cdashline{5-5} \hhline{----~----}
$B-a_i-1$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & & & & &\\
\cdashline{5-5} \hhline{----~----}
$B-a_i$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & & & & &\\
\cdashline{5-5} \hhline{----~----}
$B-a_i+1$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & & & & &\\
\cdashline{5-5} \hhline{----~----}
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\multicolumn{1}{:c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{} & \multicolumn{1}{c:}{}\\
\cdashline{5-5} \hhline{----~----}
$B$ & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} & \multicolumn{1}{!{\hspace*{-0.4pt}\vrule\tikzmark{start3}}c!{\vrule\tikzmark{end3}}}{} &  & & & &\\
\cdashline{5-5} \hhline{----~----}
\multicolumn{1}{c}{} & \multicolumn{8}{c}{\upbracefill}\\[-1ex]
\multicolumn{1}{c}{} & \multicolumn{8}{c}{$\scriptstyle k>j$}\\
\end{tabular}


\end{document}

In the places, where twice-heating is needed I put symbol of infinity, but it's better to look on the picture above.

P.S.: Sorry for my English. It's not good enough.

  • 1
    Welcome to TeX SX! Just a question: will there be text in the hatched cells? – Bernard Aug 1 '19 at 22:30
  • Hello! :) There will be no text in hatched cells, just hatching! – innokentijglum Aug 2 '19 at 8:09
4

I propose a solution based on tabularx, bigdelim and pstricks-add The general idea is to define empty nodes in the relevant cells, shifted to the lower left corner of the cell it belongs to, then to link these cells by closed polygonal paths, which are filled with one of the hatch fill styles.

\documentclass[t12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}
\usepackage{amssymb,amsmath}
\usepackage{amsthm}
\usepackage{arydshln}
\usepackage{hhline}
\usepackage{multirow, bigdelim}
\usepackage{graphicx}
\usepackage[margin=2cm]{geometry} % just for the example
\usepackage[upright]{fourier}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\newcolumntype{Y}{>{$}X<{$}}
\usepackage{tikz}
\usetikzlibrary{calc,shadings,patterns}
\usepackage{pstricks-add}
\newcommand{\mynode}[1]{\pnode[-6.2pt, -5.6pt]{#1}}
\newcommand{\mycline}{\cline{2-5}\cdashline{6-6}[2.5pt/2pt]\cline{7-9}\cdashline{10-10}[2.5pt/2pt]\cline{11-11}}

\begin{document}

\renewcommand{\arraystretch}{1.5}
\setlength{\dashlinedash}{3pt}
\setlength{\dashlinegap}{2pt}
\noindent \begin{tabularx}{\linewidth}{l|>{$}p{15mm}<{$}|*{9}{Y|}l}
    \mycline
    & &\mynode{H01} 1 & 2 & 3 & \mynode{D0} ... & a_i & a_i + 1 & \mynode{H07} a_i + 2 & \mynode{H08} ... & B & \mynode{B1}\\
    \mycline
     \ldelim\{{5.2} {3.3em}[$ k < l_i $]& 1 &\mynode{H11} & \mynode{H12}& & & & & \mynode{H17} & \mynode{H18} & &\hskip-0.33em\rdelim\}{9.4}{*}[ $ k < j-a_i $]\\
    \mycline
    & 2 & & \mynode{H22}& \mynode{H23} & & & & & \mynode{H28}& \mynode{H29}\\
    \mycline
    & 3 & & & \mynode{H33} & \mynode{D3} & & & & & \\
    \mycline
     & ⋮& & & & & & & & & \\
    \mycline
    & l_{i-1} & \mynode{H51}& & & \mynode{D5} & & & & & \mynode{H59} \\
    \mycline
    & l_i & & & & & & & & &\mynode{H69} & \mynode{B6}\\
    \mycline
    & l_{i + 1} & & & & & & & & & \\
    \mycline
     & ⋮ & \mynode{H81} & & & \mynode{D8} \mynode{H85} &\mynode{H86} & & & & \\
    \mycline
    & B-a_i - 1 & & & & \mynode{H95} & \mynode{H96} & \mynode{H97}& & &\mynode{H9a} & \mynode{B9}\\
    \mycline
    & B-a_i & & & & & \mynode{Ha6} & \mynode{Ha7} & \mynode{Ha8}& & \\
    \mycline
    & B-a_i + 1 & & & & & & \mynode{Hb7} & \mynode{Hb8} & \mynode{Hb9}& \\
    \mycline
   & ⋮ & & & & & & & \mynode{Hc8} & \mynode{Hc9} & \mynode{Hca} \\
    \mycline
   & B &\mynode{B} & & & & & & &\mynode{Hd9} & \mynode{Hda} \\
    \mycline 
        \end{tabularx}
    \psset{linestyle=none, hatchwidth=0.4pt, hatchsep=1.6pt}
    \pspolygon[fillstyle=vlines] (H01)(H11)(H12)(H22)(H23)(H33)(D3)(D5)(H59)(H29)(H28)(H18)(H17)(H07)%(K) %
    \psset{fillstyle=hlines}
    \pspolygon(H51)(D5)(H85)(H86)(H96)(H97)(Ha7)(Ha8)(Hb8)(Hb9)(Hc9)(Hca)(Hda)(B)
    \pspolygon(H69)(B6)(B9)(H9a)
    \psset{fillstyle=crosshatch*,fillcolor=black, hatchcolor=white,hatchwidth=1.6pt,hatchsep=1.6pt, hatchangle=0}
    \pspolygon(H11)(H12)(H22)(H23)(H33)(D3)(D5)(H51)
    \pspolygon(H07)(H17)(H18)(H28)(H29)(H69)(B6)(B1)
    \psbrace[ref=c, nodesepB=0.5em, braceWidthInner=4pt, braceWidthOuter=6pt](B)(Hda){$k > j$}

\end{document} 

enter image description here

| improve this answer | |
  • Thousands thanks for your help!!! I really appreciate it! But I have some problems with running your program... – innokentijglum Aug 3 '19 at 14:25
  • Thank you, Bernard for your program! I have solved the problem with launching your program and I have runned it. I use MikTeX. But I have questions about the picture of table: 1) Is there another picture of twice-hatched (cross-hatched) cell? I'm sorry, but this one look like grid instead of twice-hatched (cross-hatched) cell. 2) How can I change solid vertical lines to the dashed vertical lines between row "3" and "l_(i-1)", "l_(i+1)" and "B-a_i-1" and etc? Thanks in advance! – innokentijglum Aug 3 '19 at 16:10
  • You cannot compile with pdflatex (except with auto-pst-pdf and the switch pdflatex --shell-escape) because pdflatex cannot make the calculations required by postscript - you have to compile either the classic way, via latex->dvips->pstopdf, or with xelatex. – Bernard Aug 3 '19 at 16:15
  • Hi, Bernard! Thanks for your quick answer! I handled this problem by using xelatex. There is such option in MikTeX. – innokentijglum Aug 3 '19 at 16:27
  • For a twice-hatched area, you can use \pspolygon[fillstyle=vlines](...), then again with the other fill pattern: \pspolygon[fillstyle=hlines](...) (for the same polygon, of course). – Bernard Aug 3 '19 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.