Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there any way in latex to scan a cell of a table with horizontal, vertical, diogonal with lines?

I want similar thing as in below figure.

Thanks.

table

share|improve this question
1  
What do you mean by scan? –  Bernard Jul 24 at 11:26
    
Maybe “fill” rather than ”scan”? –  egreg Jul 24 at 12:47

2 Answers 2

up vote 1 down vote accepted

Something like this. matrix of nodes is used where a table style is defined then each node can have its own pattern given with coloring capability. A special pattern called mixed is defined as a macro taking two cell-position arguments

enter image description here

Code

\documentclass[border=10pt]{standalone}%{article}
\usepackage{tikz,siunitx}
\usetikzlibrary{matrix,positioning,calc}
\usetikzlibrary{patterns}
\tikzset{ 
table/.style={
  matrix of nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={draw,rectangle,text width=2cm,align=center},
  text depth=1.5ex,
  text height=4.5ex,
  nodes in empty cells
}
}

\newcommand{\mixed}[2]{
\foreach \i in {1,2,...,11}
{
\draw[] ([xshift=\i mm]mat-#1-#2.south west) -- ([xshift=\i mm]mat-#1-#2.north west);
}
\fill[pattern=horizontal lines]([xshift=11 mm]mat-#1-#2.south west)-- (mat-#1-#2.north east)--(mat-#1-#2.south east);
\fill[pattern=north east lines]([xshift=11 mm]mat-#1-#2.south west)-- (mat-#1-#2.north east) -- ([xshift=11 mm]mat-#1-#2.north west);
}

\begin{document}

\begin{tikzpicture}
% the matrix entries
\matrix (mat) [table]
{
 \node[pattern=fivepointed stars,pattern color=green,]{};  &   & 
 \node[pattern=crosshatch dots,pattern color=red]{};       &  &  \\
   &   \node[pattern=dots,pattern color=blue]{};           &  &
  \node[pattern=north west lines,pattern color=red]{};  &        \\
   &   &\node[pattern=north east lines,pattern color=brown]{};  &  
      \node[pattern=horizontal lines]{}; &                       \\
   & \node[pattern=bricks,pattern color=red]{};  &  &
      \node[pattern=vertical lines,pattern color=red]{}; 
   &                                                             \\
};
\mixed{4}{1}
\mixed{3}{5}
\end{tikzpicture}

\end{document}
share|improve this answer

You can do this easily enough with tikz/PGF. What I have drawn is a little squarer than your diagram but you can scale it if you wish (using, for example, \begin{tikzpicture}[xscale=1.2]).

enter image description here

Here's the latex code (the only slighty tricky bit is the triangle):

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
  \draw(0,0) grid (4,4);
  \filldraw[pattern=horizontal lines] (0,1) rectangle (1,2);
  \filldraw[pattern=vertical lines] (1,0) rectangle (1.25,1);
  \filldraw[pattern=vertical lines] (2,0) rectangle (3,1);
  \fill[pattern=horizontal lines](1.25,0)--(2,1)--(2,0);
  \fill[pattern=north east lines](1.25,0)--(2,1)--(1.25,1);
  \filldraw[pattern=north east lines](2,2)rectangle(3,3);
\end{tikzpicture}

\end{document}

The grid spacing that I have used is the tikz default. If you need to change this to be more like your picture then have look at TikZ patterns with dimensions parameters.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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