# [Tex/LaTex] TIKZ: only fill 75% of the node-background with color

backgroundscolortikz-pgftikz-styles

I want to use some background color on my node, but not for the whole node. Just for 75% of the node.

My code is this:

\documentclass[tikz,margin=5mm]{standalone}
\begin{document}
\tikz\node[draw, fill=gray!30]{Some Text};
\end{document}


Which produces this:

But I want more something like this:

Edit: The white and the grey part should be reversed in the second image.

You can use path picture and path picture bounding box:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikz
\node[draw]
[path picture={
\fill[gray!30](path picture bounding box.north west)rectangle
($(path picture bounding box.north east)!.75!(path picture bounding box.south east)$);
}](n)
{Some Text}
;
\end{document}


This works also if the node is a circle:

or a cloud (options: cloud,cloud ignores aspect, needs library shapes.symbols):

Only if the node is a rectangle, you can use the node name instead path picture bounding box:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikz
\node[draw]
[path picture={
\fill[gray!30](n.north west)rectangle($(n.north east)!.75!(n.south east)$);
}](n)
{Some Text}
;
\end{document}


Update (because of a comment)

If the background should be colored in an intervall, eg. from 0.3 to 0.8, use

($(<name>.north west)!.3!(<name>.south west)$)
rectangle
($(<name>.north east)!.8!(<name>.south east)$);


Replace <name> by the node name or path picture bounding box.

Code:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikz
\node[draw]
[path picture={
\fill[gray!30]
($(path picture bounding box.north west)!.3!(path picture bounding box.south west)$)
rectangle
($(path picture bounding box.north east)!.8!(path picture bounding box.south east)$);
}](n)
{Some Text}
;
\end{document}