答案1
我认为基本方案更好,如下所示:
\tikz[remember picture,
baseline=(color.base)%<-----------------------added
]
\documentclass{article}
\usepackage{tikz}
\newcommand{\ccor}[1]{%
\tikz[remember picture,baseline=(color.base)]{%
\node[fill=black!20,anchor=base](color){#1};%
}%
}
\begin{document}
write some text with \ccor{color background}.
\end{document}
答案2
我已将命令更改为:
\newcommand{\ccor}[1]{%
\tikzmarknode{pos}{\vphantom{AA}}
\tikz[remember picture,overlay]{%
\node[fill=facebook!20,anchor=west](codigo)at (pos.west){\texttt{#1}};
}
\sbox0{\hphantom{#1}}
\hspace{\wd0}
}
结果令人满意。