文本中的 tikz 节点略微凸起

文本中的 tikz 节点略微凸起

我定义了以下命令:

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

它运行良好,唯一的问题是,当我将其嵌入普通文本时,它看起来略微凸起,弄乱了行距。有没有办法解决这个问题,让嵌入的 tikz 垂直居中?

答案1

如果您不想一直使用相同的节点名称 (P),则可能需要稍微调整一下新命令。设置不同的基线可以解决您的问题。您可以在文档中详细了解 tikz 如何设置它。

\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}

结果是

在此处输入图片描述

相关内容