[Tex/LaTex] Symbol not in line with text

fontsizescalingsymbolsvertical alignment

I'm using this solution of this question for printing a warning sign. But the text and the Symbol are vertically not correct algigned aligned in my special case.

I want to have the same lower baseline for the symbol as for letters like (a, b, c) and not (q, p, g, y). The upper baseline is okay for me.

Not so nice veritcally aligned sign

Best Answer

See edited answer at the end, with a cleaner and adaptative solution

Quick, dirty, and very explicit, but it works :

\documentclass{article}
    \usepackage{fourier}
    \usepackage{graphicx}

\begin{document}
    \raisebox{0.325ex}{\resizebox{!}{1.2ex}{\danger}} dasdfcsdasda
\end{document}

enter image description here

of course, it need to be adapted according to the font you use...


Explanations:

1. Initial state: \danger dasdfcsdasda

enter image description here

2. First, we need to reduce the size of the warning sign.

It is achieved through the macro \resizebox{width}{height}{what is to be resized} (of the graphicx package) where the argument ! is used to keep proportions the same. As first approximation, we took:

\resizebox{!}{1ex}{\danger} dasdfcsdasda

enter image description here

3. However, we observe that the resizebox keep the resized symbol bottom-aligned with the original one.

We thus need to "raise" is, using \raisebox{length}{content to be raised}. As first approximation, we used:

\raisebox{0.3ex}{\resizebox{!}{1ex}{\danger}} dasdfcsdasda

enter image description here

4. Finally, we fiddled the length in order to get something more correct


Edit

Here is an adaptative solution that assess the lengths according to current context (font family, and size).

\documentclass{article}

    \usepackage{graphicx}%                                          to access \settoheight and \settodepth macros

    \usepackage{fourier}%                                           to access \danger icon
    \usepackage{libertine}%                                         set serif font
    \usepackage{roboto}%                                            set sans-serif font (different height)

    \newlength{\myheight}
    \newlength{\mydepth}

    \newcommand{\myDanger}{%
        \settoheight{\myheight}{l}%                                 in order to get the maximal height of letters in the font used
        \settodepth{\mydepth}{\danger}%                             in order to retrieve the actual baseline
        \resizebox{!}{\myheight}{\raisebox{\mydepth}{\danger}}%     seems counterintuitive to me (I'd have resized, then raised... but well, it works, so... !)
    }

\begin{document}
    \myDanger dasdfcsdasda

    {\sffamily \myDanger dasdfcsdasda}

    {\Huge \sffamily \myDanger dasdfcsdasda}

    {\Huge \myDanger  dasdfcsdasda}

    {\Huge\myDanger{\sffamily\myDanger}}
\end{document}

enter image description here