# tikz node in text is slightly raised

I have defined the following command:

\pgfkeys{tikz/protein/.style={fill=#1,shape=rectangle,rounded corners}}
\newcommand{\protein}[2]{
\protect\tikz \protect\node [protein=#1] {\small{#2}};}


It works fine, the only problem I have is that when I embed it in normal text, it appears slightly raised, messing up the line spacing. Is there any way to fix that, so that the embedded tikz is vertically centered on the line?

-

You may have to adjust your newcommand a bit if you don't want to use the same node name (P) all the time. Setting a different baseline solves your problem. You can read in more detail in the documentation about how tikz sets it.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\pgfkeys{tikz/protein/.style={fill=#1,shape=rectangle,rounded corners}}
\newcommand{\protein}[2]{%
\protect\tikz[baseline=(P.base)] \protect\node [protein=#1] (P) {\small{#2}};}
I need to produce some text to have at least three lines to test how that looks. So I am just writing a lot of useless stuff
text text text text \protein{red}{H} more text here. And even more following that. It seems that the base is the best thing to align to in this case

\end{document}


Results in

-
Just what I was looking for! Thanks! –  Björn Pollex Jan 25 '11 at 15:19
You should add a % after \newcommand{\protein}[2]{ to avoid the extra space in front of the protein. In your example you write text\protein{red}{H} more, which should be text \protein{red}{H} more, shouldn't it? –  Martin Scharrer Jan 25 '11 at 16:37
Scharrer true indeed, I changed it. Two wrongs don't make a right :-) –  Martin H Jan 25 '11 at 16:49