1

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)

My Goal

Zarko
  • 296,517
Alberto
  • 464

2 Answers2

2

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).

pattern

\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).

Alberto
  • 464
TeXnician
  • 33,589
2

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

\documentclass[x11names, svgnames, border=3pt]{standalone}
\usepackage{pst-grad,pst-text, auto-pst-pdf}

\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}

enter image description here

Bernard
  • 271,350
  • is similar possible with TikZ? I liked your solution very much (+1), but I'm not familiar with postcripts ... – Zarko Feb 05 '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 06 '17 at 00:06
  • 1
    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 06 '17 at 00:36
  • Maybe you should ask a specialist if there exists the equivalent of \pscharpath, which turns a character into a closed path. – Bernard Feb 06 '17 at 00: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 06 '17 at 15:27