# Pattern background in table cell or minipage

More than a code answer, I am asking for pointers. What packages should I look into to get something similar with the image? The hard part (I think) is the stripped background. The digit, then is just placement with white color. (btw, using XeLaTeX)

I just want to point you to the patterns library of tikz. The following code and result could be a starter for you (BTW see here for similar question).

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

\begin{document}
\begin{tikzpicture}
\draw[fill=gray!50] (0,0) rectangle (4,2);
\draw[pattern=horizontal lines,pattern color=black] (0,0) rectangle (4,2);
\node[color=white,scale=8] at (2,1) {1};
\end{tikzpicture}

\end{document}


It seems it is not possible to change a pattern line width. But one can look into the pgf patterns file (pgflibrarypatterns.code.tex), copy the pattern definition, and change the line width:

\pgfdeclarepatternformonly{my horizontal lines}{\pgfpointorigin}{\pgfqpoint{100pt}{1pt}}{\pgfqpoint{100pt}{3pt}}%
{
\pgfsetlinewidth{1pt}
\pgfpathmoveto{\pgfqpoint{0pt}{0.5pt}}
\pgfpathlineto{\pgfqpoint{100pt}{0.5pt}}
\pgfusepath{stroke}
}


and change the code above to use this pattern name (my horizontal lines).

• How to set linewidth? Trying \pgfsetlinewidth{50mm} with no luck. Thanks. – Alberto Feb 6 '17 at 15:47
• @Alberto I don't actually know, but you could try to make a bigger rectangle and then scale it down (just Q&D). – TeXnician Feb 6 '17 at 15:49
• Completed your answer with line width info. May take some time before it is peer reviewed. – Alberto Feb 6 '17 at 15:56

Here is a way to obtain such a pattern background with pstricks:

\documentclass[x11names, svgnames, border=3pt]{standalone}

\begin{document}

\begin{postscript}
\psset{framesep=4pt, linewidth=0.4pt}
\psframebox[framesep=-0.05pt, fillstyle=solid, fillcolor=Lavender!75, linecolor=LavenderBlush4]{\psframebox[fillstyle=hlines, hatchangle =0, hatchsep=1.5pt, hatchcolor=LavenderBlush4, linecolor=LavenderBlush4]{\hspace{0.6cm}%
\pscharpath[fillstyle=solid, fillcolor=white]{\fontsize{120pt}{120pt}\selectfont\bfseries 4}}}
\end{postscript}

\end{document}


• is similar possible with TikZ? I liked your solution very much (+1), but I'm not familiar with postcripts ... – Zarko Feb 5 '17 at 23:59
• The postscript is here for auto-pst-pdf, which enables compilation with pdflatex. The pspicture environment would be OK with latex or xelatex. That said, with TikZ, I suppose yes, but I don't know it well – actually I only use tikz-cd for commutative diagrams, and I always found pstricks simpler to use. Doesn't the tikz code of the answer below do more or less the same thing? – Bernard Feb 6 '17 at 0:06
• Answer with TikZ do almost the same, but the number is not outlined. I can reproduce your solution with TikZ, but without outlined number. – Zarko Feb 6 '17 at 0:36
• Maybe you should ask a specialist if there exists the equivalent of \pscharpath, which turns a character into a closed path. – Bernard Feb 6 '17 at 0:42
• There is bidicontour (not Tikz, though), that I am already using. But in fact, not sure if the number path is required. Will try to apply the TIkz answer in my document and report soon. – Alberto Feb 6 '17 at 15:27