# TikZ: Draw a partially filled text node, i.e. a progress bar with text inside

I would like to draw a node around a one-line text, with only the left part filled. The size of that 'left part' would be specified by some fraction. In effect, this would be a progress bar with text inside.

\documentclass{article} \usepackage{tikz} \begin{document}
\begin{tikzpicture}

\draw (0, 0) node[draw, fill = green!10, fill fraction = .7] {Some
text};

\end{tikzpicture}
\end{document}


Of course my fictitious option 'fill fraction', which should say that only the leftmost 70% should be filled, gets ignored.

It is so cruel that TikZ ignored you, I had to do something about it. ;-)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[fill fraction/.style n args={2}{path picture={
\fill[#1] (path picture bounding box.south west) rectangle
($(path picture bounding box.north west)!#2!(path picture bounding box.north east)$);}}]

\draw (0, 0) node[draw, fill fraction={green!10}{0.7}] {Some
text};
\draw (4, 0) node[circle,draw, fill fraction={green!10}{0.7}] {Some
other text};
\end{tikzpicture}
\end{document}


• Very efficient thank you ! Can you help us understand how it works ? – joseldsm Mar 7 '19 at 7:43
• @joseldsm I just add a path picture. This is something that is drawn on the background and clipped against the node boundary path. – user121799 Mar 7 '19 at 14:40
• Nice and simple! In my case, I wanted to fill the white portion of the circle with another color (say red). You can fill the entire circle first by adding \draw node[circle, draw, fill={red}] before the \draw command that uses fill fraction – Addison Klinke Jul 25 '20 at 23:50