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?

1

2 Answers 2

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
  • I didn't mention before, but I would like the figure to scale when using different font sizes like \Large. I believe this measures the descent of a normal g always.
    – mendus
    Commented Jan 30, 2018 at 15:01
  • @mendus I edited to measure the current font size Commented Jan 30, 2018 at 15:01
  • @StevenB.Segletes it would be nice to add a g too next to f. (+1)
    – koleygr
    Commented Jan 30, 2018 at 15:03
  • @koleygr Done, per request. Commented Jan 30, 2018 at 15:04
  • 1
    @StevenB.Segletes It looks fine now, the result is what I was looking for, so I'll accept the answer. Anyway, I wonder if creating the dummy box can be avoided, and inquire the current font about those values.
    – mendus
    Commented Jan 30, 2018 at 15:11
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

1
  • Seems similar to the other approach but without creating a box. Works well too.
    – mendus
    Commented Jan 30, 2018 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .