TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have defined the following command:

\pgfkeys{tikz/protein/.style={fill=#1,shape=rectangle,rounded corners}}
  \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?

share|improve this question
up vote 7 down vote accepted

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.


\pgfkeys{tikz/protein/.style={fill=#1,shape=rectangle,rounded corners}}
  \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


Results in

enter image description here

share|improve this answer
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

Your Answer


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.