5

I currently have the following TikZ code:

\documentclass{scrbook}

\usepackage{tikz}

\begin{document}


\tikzset{
     tlstartyear/.style={
         name=tlstartyear,
         above=5pt,
         inner xsep=0pt,
         anchor=base west,
     }     
}      

\tikz{
     \fill [blue] (0,0)
        ++(3em,0pt)
        node [tlstartyear] {Some text}
        node {$\bullet$};
}


\end{document}

which (thanks to Jake) produces:

not centered

How can I center the text with the node?

I've tried playing with align=center, align=flush center, right and left, without success...

1

2 Answers 2

7

Change anchor=base west to anchor=base in \tikzset. Or, if you want to preserve the base west anchor in \tikzset for other nodes, use node [tlstartyear,anchor=base] {Some text}.

1
  • Ah, thanks! I can only upvote your answer in 3 hours (max votes reached for today).
    – raphink
    Sep 29, 2011 at 20:23
0

It seems that if you simply remove the anchor=base west things just work:

\tikzset{
     tlstartyear/.style={
         name=tlstartyear,
         above=5pt,
         inner xsep=0pt,
         %anchor=base west,
     }     
}      

In the original solution, I had replaced above=5pt with above. As @Gonzalo pointed out, this has nothing to do with horizontal alignment. To me it looks better if you replace above=5pt, with just above, but that is subjective, so have reverted that back in the code above. The image shown is with using the above option without a length.

enter image description here

2
  • In the original code the anchor is set to base west, not simply base (in fact, removing west and using only base gives the desired horizontal alignment). I don't see why changing above=5pt to above has anything to do with the horizontal alignment. Sep 29, 2011 at 20:41
  • @Gonzalo: You are absolutely correct. I normally just use above without the option length so that is what I tried and it looked better to me. Will add this as a comment. Sep 29, 2011 at 20:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .