How to draw ░░░░░░░ blank with overlaid text in 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.)

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns}
\newcommand{\PlaceCharOverDots}[2][10]{%
\begin{tikzfadingfrompicture}[name=temp]
\node[transparent!20,scale=#1] 
{\bfseries\sffamily \textcolor{white}{#2}};
\end{tikzfadingfrompicture}%
\tikz[baseline=(X.base)]{\node[inner sep=0pt,outer sep=0pt,scale=#1] (X) {\bfseries\sffamily 
\textcolor{white}{\strut#2}};
\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);}%
}
\begin{document}
\PlaceCharOverDots{Hello world} 
\end{document}

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.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{tikzmark,patterns}
% based on the rings example on p. 1060 of the pgfmanual as well as 
% https://tex.stackexchange.com/a/29367/1952 for the color
\makeatletter 
\pgfdeclarepatternformonly[/tikz/radius,\size]{flexible dots}
{\pgfpoint{-0.5*\size}{-0.5*\size}}
{\pgfpoint{0.5*\size}{0.5*\size}}
{\pgfpoint{\size}{\size}}
{
 \pgfsetfillcolor{\tikz@pattern@color}
 \pgfpathcircle\pgfpointorigin{\pgfkeysvalueof{/tikz/radius}}
 \pgfusepath{fill}
}
\makeatother
\tikzset{
radius/.initial=0.1pt,
size/.store in=\size, 
size=0.5pt,
}
\begin{document}
\tikzmarknode[pattern=flexible dots,inner sep=2pt]{test}{Hello world}
\end{document}

enter image description here


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.

   documentclass{article}
    \usepackage{xcolor}
    \usepackage{tikz}
    \usetikzlibrary{patterns}
    \pgfdeclarepatternformonly{my dots}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{5pt}{5pt}}{\pgfqpoint{2pt}{2pt}}%
    {
        \pgfpathcircle{\pgfqpoint{0pt}{0pt}}{.4pt}
        \pgfusepath{fill}
    }
    \newcommand{\fade}[1]{%
    \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};
    \end{tikzpicture}}
    \begin{document}
    \ \\
    I \fade{Hello World} am a blank space.\\
    I Hello World am a blank space.
    \end{document}

Dot pattern behind Hello World.

Tags:

Text

Tikz Pgf