# Expanding a Tikz rectangle to fill remaining text width

I would like to place a shaded rectangle between the left and right footers, which fills the space in-between. The left footer can be of variable width, so I would like the rectangle to automatically fill however much space is remaining.

The following code demonstrates what I want to do (with the centre footer forming part of the left footer), but the width of the rectangle is fixed. I would like to change the rectangle's width to fill the remaining space automatically.

\documentclass{article}

\usepackage{tikz}
\usepackage{fancyhdr}

\fancyhf{}
\pagestyle{fancy}
\rfoot{1 of 10}

\lfoot{
This text can be of variable width
\hspace{5pt}
% The value below of 2in should change to fill the remaining space
}

\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}


For info, I am actually using this code in a class, which is why the left footer text can change (between different documents).

I am using xelatex, although I don't think that makes any difference.

-

If you don't mind putting the variable-width text into a node, then it is relatively easy. You can adjust the spacing to your liking further.

\documentclass{article}

\usepackage{tikz,fancyhdr,lipsum}
\usetikzlibrary{calc}

\fancyhf{}
\pagestyle{fancy}
\rfoot{1 of 10}

\lfoot{%
\tikz[baseline=(a.text)]{
node[outer xsep=0,inner xsep=0,
append after command={
let \p1=($(a.east)-(a.west)$),
\n1={veclen(\x1,\y1)},
\n2={width(" 1 of 10 ")}
in
([xshift=5pt]a.south east|-a.text)
rectangle
++({(\textwidth-(\n1+\n2+5)*1pt)},2pt)
}
] (a)
{This text can be of variable width};
}%
}

\begin{document}
\lipsum[1-15]
\end{document}


-
Wow, you're an absolute star, thank you. I spent literally hours on that! Will up-vote once my reputation score is high enough ;-) – abeverley Mar 31 '14 at 8:50
@abeverley My pleasure. – percusse Mar 31 '14 at 9:06