Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Perfect, thank you! –  ℝaphink Apr 15 '11 at 21:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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