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.

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?

share|improve this question

1 Answer 1

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.

\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

enter image description here

share|improve this answer
    
Just what I was looking for! Thanks! –  Björn Pollex Jan 25 '11 at 15:19
1  
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

 
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.