4

This question led to a new package:
fancytabs

I have a node positioned in a shaded rectangle with:

\newcommand{\tabstyle}{\Large\scshape}
\newcommand{\tabheight}{4cm}
\newcommand{\tabwidth}{1cm}
\newcommand{\tabcount}{6}
\newcommand{\tableftcolor}{white}
\newcommand{\tabrightcolor}{gray!50}
\newcommand{\tabtop}{\tabheight}
\newcommand{\tabtextpos}{0.5}
\newcommand{\fancytab}[2]{%
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift={-\tabtop-1*mod(#2-1,\tabcount)*\tabheight},
                  xshift=-0.5*\tabwidth]
      at (current page.north east) {
      \tikz\shade[shading=axis,bottom color=\tableftcolor,
                  top color=\tabrightcolor,shading angle=-90]
        (0,0) rectangle (\tabwidth,\tabheight)
           node[rotate=90,pos=\tabtextpos] {\tabstyle#1};
    };
  \end{tikzpicture}%
}

Typically, when \tabtextpos has value 0.5, the text is centered in the shape, both vertically and horizontally:

0.50, centered

Now if I used 0.38 to put it more to the left, I get:

0.38, not centered

which is more to the left, but also down.

How could I put it to the left while still keeping it centered vertically?

Edit:

This code is now part of a module called fancytabs, available on CTAN.

2

The factor you give is between the given rectangle path coordinates (0,0) and (\tabwidth,\tabheight). This moves it diagonal. If you don't want that you need to place it either using a different path (which doesn't has to draw anything), i.e. between (0,.5*\tabheight) and (\tabwidth,.5*\tabheight) or better directly:

  \tikz\shade[shading=axis,bottom color=\tableftcolor,
                  top color=\tabrightcolor,shading angle=-90]
        (0,0) rectangle (\tabwidth,\tabheight)
           node [rotate=90] at (\tabtextpos*\tabwidth,.5*\tabheight) {\tabstyle#1};

Note that in this implementation \tabtextpos must be numeric, while before it could also be a string like 'midway', 'near end', etc.

You could also the calc tikzlibrary syntax: ($ (0,.5*\tabheight) ! \tabwidth ! (\tabwidth,.5*\tabheight) $), but for this usage this would be overkill.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.