8

I'm creating a few custom icons for my latex documents that are repeated using tikz.

However, in order to align them to the text I need to know the descent to set the baseline in the correct place. I also want the descent to be calculated depending on font size.

the measures needed I might need other measures from that picture too.

Here is one example.

\documentclass{article}
\usepackage{tikz}
\newcommand{\increasing}{%
\begin{tikzpicture}[baseline=0]
\draw[->] (0,0) -- (1ex,1em);
\end{tikzpicture}
}
\begin{document}
f \increasing
\end{document}

I want the arrow to be lower, so I need to set baseline=descent in the tikzpicture. How can I do that? Any documentation of the rest of the heights?

mendus
  • 261

2 Answers2

7

Something like this?? I set the baseline to the depth of the g descender and the top of the arrow to the height of the X, using the active font size.

\documentclass{article}
\usepackage{tikz}

\newcommand{\increasing}{%
\setbox0=\hbox{Xg}%
\begin{tikzpicture}[baseline=\dp0]
\draw[->] (0,0) -- (1ex,\dimexpr\ht0+\dp0\relax);
\end{tikzpicture}
}
\begin{document}
\Large fg\increasing
\normalsize fg\increasing
\tiny fg\increasing
\end{document}

enter image description here

7

You can measure the maximum descender:

\documentclass{article}
\usepackage{tikz}

\newcommand{\showbaseline}{%
  \settodepth{\alphabetdepth}{fgjpqy}
  \makebox[0pt][l]{\vrule width 5cm height -\alphabetdepth depth \dimexpr\alphabetdepth+0.1pt\relax}%
  \ignorespaces
}

\newlength{\alphabetdepth}
\newcommand{\increasing}{%
  \settodepth{\alphabetdepth}{fgjpqy}%
  \begin{tikzpicture}[baseline=\alphabetdepth]
  \draw[->] (0,0) -- (1ex,1em);
  \end{tikzpicture}%
}
\begin{document}

\showbaseline
f \increasing\quad {g \increasing} {\itshape f \increasing}

\bigskip

{\LARGE\showbaseline f \increasing\quad g \increasing}

\bigskip

{\tiny \showbaseline\itshape f \increasing}

\end{document}

The \showbaseline command is just for making clear where the maximum depth is located.

enter image description here

egreg
  • 1,121,712