# Tikz fill double line with pattern not with color

I'd like to fill the inner of a double line path with different patterns: hatch, random dots, Poisson discs, grid.

Consider following hexagon, where I would like to fill the inner of the edges.

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\def\h{2}
\def\l{1}
\def\t{0.1} % thickness
\def\strokewidth{0.01cm}

\coordinate (A) at (0,0);
\coordinate (B) at ($(A) + (-30:\l)$);
\coordinate (C) at ($(B) + (0,-\h)$);
\coordinate (D) at ($(C) + (-150:\l)$);
\coordinate (E) at ($(D) + (150:\l)$);
\coordinate (F) at ($(E) + (0,\h)$);
\coordinate (A1) at ($(A) + (0,\h/2)$);
\coordinate (B1) at ($(B) + (30:\l/2)$);
\coordinate (C1) at ($(C) + (-30:\l/2)$);
\coordinate (D1) at ($(D) + (0,-\h/2)$);
\coordinate (E1) at ($(E) + (-150:\l/2)$);
\coordinate (F1) at ($(F) + (+150:\l/2)$);
\draw[line width=\strokewidth, double=none, double distance=\t*1cm-2*\strokewidth]
(A) -- (B) -- (C) -- (D) -- (E) -- (F) -- cycle
(A) -- (A1)
(B) -- (B1)
(C) -- (C1)
(D) -- (D1)
(E) -- (E1)
(F) -- (F1)
;
\end{tikzpicture}
\end{document}


I know that tikz documentation states, that the double line is achieved by drawing two solid lines above each other with different line thickness. So this means a more complicated solution is probably required.

Relevant question could be Making the filling / gap between double border lines transparent

-
Lines as PDF objects are not seen as objects which have areas, so filling them is technically not possible right away, in fact that's why double line is possible. However you can decorate the path via postaction as a quick fake on top of the solid draw. – percusse Jul 23 '14 at 12:00

It is not possible to fill a line, only an area. So here is a kind of crazy idea. Transform each "line" in your drawing into a rectangle wich can be filled at will.

The following code implements a macro called \tikzsegment which uses a rectangular node to "draw" a line. It gets three parameters:

1. Tikz styles for the node (here you can specify the pattern, fill color, etc. and the "minimum height" of the node, which will be the resulting "line" widht)
2. Coordinates of the starting point (can be a named node)
3. Coordinates of the ending point

Note that instead of the standard syntax \draw[styles] (a) -- (b), you have to use now \tikzsegment{styles}{a}{b}, so you lose the ability of drawing several lines in a single path (and you cannot close the path). However you can combine your previous technique to draw the required path (and its borders), and apply later this technique to fill each segment, as I did in the following example:

\usetikzlibrary{calc}
\usetikzlibrary{patterns}

\def\tikzsegment#1#2#3{ % This is the macro explained above
\path let
\p1=($(#3)-(#2)$),
\n1={veclen(\p1)}
in (#2) -- (#3)
node[minimum width=\n1,
inner sep=0pt,
pos=0.5,sloped,rectangle,
#1]
(line){};
}

\begin{tikzpicture}
% This is your code untouched
\def\h{2}
\def\l{1}
\def\t{0.1} % thickness
\def\strokewidth{0.01cm}

\coordinate (A) at (0,0);
\coordinate (B) at ($(A) + (-30:\l)$);
\coordinate (C) at ($(B) + (0,-\h)$);
\coordinate (D) at ($(C) + (-150:\l)$);
\coordinate (E) at ($(D) + (150:\l)$);
\coordinate (F) at ($(E) + (0,\h)$);
\coordinate (A1) at ($(A) + (0,\h/2)$);
\coordinate (B1) at ($(B) + (30:\l/2)$);
\coordinate (C1) at ($(C) + (-30:\l/2)$);
\coordinate (D1) at ($(D) + (0,-\h/2)$);
\coordinate (E1) at ($(E) + (-150:\l/2)$);
\coordinate (F1) at ($(F) + (+150:\l/2)$);

\draw[line width=\strokewidth, double=none, double distance=\t*1cm-2*\strokewidth]
(A) -- (B) -- (C) -- (D) -- (E) -- (F) -- cycle
(A) -- (A1)
(B) -- (B1)
(C) -- (C1)
(D) -- (D1)
(E) -- (E1)
(F) -- (F1)
;

% This is the new code to fill each segment
\coordinate (prev) at (F);
\foreach \vertex in {A,B,C,D,E,F} {
\tikzsegment{pattern=crosshatch dots,
pattern color=blue,
minimum height=\t*1cm}
{prev}{\vertex};
\coordinate (prev) at (\vertex);
\tikzsegment{pattern=north west lines,
minimum height=\t*1cm}
{\vertex}{\vertex1};
}
\end{tikzpicture}


This is the result:

-
I have one question: what does \vertex refers to? – Hotschke Jul 23 '14 at 12:44
@Hotschke It is the loop variable. It takes the values A, B, C ... in each iteration of the loop. – JLDiaz Jul 23 '14 at 13:00
sorry, I meant \vertex1 – Hotschke Jul 23 '14 at 13:04
@Hotschke It is the same than vertex, but with a 1 at the end :-) So it takes the values A1, B1, C1, ... – JLDiaz Jul 23 '14 at 13:17
stupid me. totally clear, trivial... . Thanks. – Hotschke Jul 23 '14 at 13:18