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).

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. – user11232 Dec 11 '13 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.