5

I want to use the current text's dimensional properties for constructing an inline TikZ image, such as an icon.
The properties I have in mind for use are

\height
\depth
\totalheight

as described here.

What I want to achieve is something like the following, but instead of using ex units, want to be sure the drawing fits into the line exactly.
bad rendering

\tikz[baseline={1ex}] \draw[draw=black, fill=blue, rounded corners] (0,0) rectangle (5ex,3ex) ;
Signal

Please observe that this code lets the drawing start too low (below the "g" in "Signal") and end too high (above the "S" in Signal).

derabbink
  • 1,640

1 Answers1

5

You can use node and control its dimensions.

\documentclass{article}
\usepackage{tikz,calc}
\begin{document}
\fboxsep=0pt
\fbox{
\tikz[baseline=(a.base)] \node[draw=black, fill=blue, rectangle, rounded corners,inner sep=0, outer sep=0,minimum width=5ex] (a) {\vphantom{Sg}} ;
Signal}
\end{document}

enter image description here

Here \vphantom adds the total height (i.e., height of S and depth of g)

PS \fbox is there just to show the heights.

  • Nice solution. Is there another way to create the \vphantom? One that does not rely on the looks of the current font (particularly the S and g letters) for spanning all the way from top to bottom? – derabbink Dec 11 '13 at 13:54
  • @derabbink calc also provides \heightof and \depthof macros, but they again rely on the font. –  Dec 11 '13 at 14:23