TIKZ: only fill 75% of the node-background with color
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}
Doing the fill in a separate step might be an option.
\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc,backgrounds,scopes}
\begin{document}
\begin{tikzpicture}
\node[draw] (a) {Some Text};
{ [on background layer]
\fill[gray!30] (a.north west) rectangle ($(a.south east)!0.3!(a.north east)$);
}
\end{tikzpicture}
\end{document}
I propose something similar: shading
\documentclass[tikz,margin=5mm]{standalone}
\begin{document}
\tikz\node[draw, top color=gray!30,bottom color=white]{Some Text};
\end{document}
EDIT
Since it was requested, here is a sample with a fading; I set the background as orange, in order to make the effect apparent
\documentclass{article}
\usepackage{pagecolor}
\usepackage{tikz}
\pagecolor{yellow!30!orange}
\usetikzlibrary{fadings}
\begin{document}
\tikzfading[name=fade down,
top color=transparent!0,
bottom color=transparent!100]
\begin{tikzpicture}[path fading=fade down]
\node[draw, fill=gray!30,path fading]{Some Text};
\end{tikzpicture}
\end{document}
With result: