Wondering how to draw this sort of thing with tikz:

I ░░░░░░░░░░░░░░░ am a blank space.

...but with text overlaid on the dot grid. Also, instead of the dot-grid being diagonal, I would like to make it simply vertical/horizontal, and make the dots smaller and lighter so when the text goes over it it's not distracting. But it would be along these lines:

I ░Hello░World░░░ am a blank space.

But the "Hello World" would have ░ faded dots behind each letter. Just using this ░ unicode character for demo, this instead would use tikz.


Are you looking for something like this? (If yes, all I'd have to do is to introduce a slightly more flexible pattern such that things look good also with more reasonable scale factors, if no, then this may help others to understand the question better.)

{\bfseries\sffamily \textcolor{white}{#2}};
\tikz[baseline=(X.base)]{\node[inner sep=0pt,outer sep=0pt,scale=#1] (X) {\bfseries\sffamily 
\path[pattern=dots,overlay] (X.north west)
rectangle (X.south east);%
\path[path fading=temp,fit fading=false,overlay,pattern=dots,pattern
color=gray!20] (X.north west)
rectangle (X.south east);}%
\PlaceCharOverDots{Hello world} 

enter image description here

EDIT: If you only want the text being placed over dots, all one needs to do is to define a somewhat denser dot pattern and to use it as the background of a node. I recommend \tikzmarknode here because it automatically detects the mode your in (math mode, font size etc.) and has other advantages, which this however does not exploit. Of course, you may adjust inner sep to your needs and/or replace it by inner xsep and inner ysep.

% based on the rings example on p. 1060 of the pgfmanual as well as 
% https://tex.stackexchange.com/a/29367/1952 for the color
\pgfdeclarepatternformonly[/tikz/radius,\size]{flexible dots}
size/.store in=\size, 
\tikzmarknode[pattern=flexible dots,inner sep=2pt]{test}{Hello world}

enter image description here

  • Pretty much, but the Hello World would just be plain black text, not a cutout of the dots. It's as if the blank is just a background made of dots, and you are typing right over it to fill in the blank. – Lance Pollard Dec 23 '18 at 1:28
  • @LancePollard I am not sure I fully understand yet but I added a proposal that among other things comes with a more flexible dot pattern. – user121799 Dec 23 '18 at 1:47
  • copy-pasting the code into pdflatex I am getting an error: ! Undefined control sequence. l.24 \tikzmarknode [pattern=flexible dots,inner sep=2pt]{test}{Hello world} – Lance Pollard Dec 23 '18 at 3:18
  • 1
    @LancePollard When was the last time you updated your TeX installation? \tikzmarknode has been added only a few months to the tikzmark library. The error message seems to indicate that you are using an older version. – user121799 Dec 23 '18 at 3:22

Here is one way to do it. The TikZ pattern has been adopted from https://tex.stackexchange.com/a/323867/8650. Instead of setting up a background layer, I simply draw the node twice.

    \pgfdeclarepatternformonly{my dots}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{5pt}{5pt}}{\pgfqpoint{2pt}{2pt}}%
    \begin{tikzpicture}[anchor=base, baseline]
    \node[inner sep=0, outer sep=0] (node) {#1};
    \fill[pattern=my dots, pattern color=black!10] (node.south west) rectangle (node.north east);
    \node[inner sep=0, outer sep=0] (node) {#1};
    \ \\
    I \fade{Hello World} am a blank space.\\
    I Hello World am a blank space.

Dot pattern behind Hello World.

  • @marmots answer is better - using a tikzmarknode and applying the pattern directly to that node -you just need the lighter color. – hpekristiansen Dec 23 '18 at 2:08

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.