Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to define nodes which are shapes with some text in it using \ce{} from the mhchem package. How would I go around ensuring the baselines are the same between nodes, right now it shifts if I use subscript. Here's a MWE:

\documentclass{article}
\usepackage[version=3]{mhchem}

\usepackage{tikz}
\usetikzlibrary{shapes}

\newbox\nodebox
\newcommand\mycommand[2]{%
    \begin{tikzpicture}%
        \node[text=#1, rectangle, inner ysep=4pt, inner xsep=2pt, rounded corners=7, minimum height=5mm, minimum width=10mm, fill=#1] {\tiny\sffamily \textbf{\ce{#2}}};
        \node[yshift=-0.5,text=black!95!white] {\scriptsize\sffamily \textbf{\ce{#2}}};
        \node[text=white] {\scriptsize\sffamily \textbf{\ce{#2}}};
    \end{tikzpicture}%
}

\begin{document}

\mycommand{red!40!white}{Al2O3} \mycommand{blue!40!white}{Al}

\end{document}
share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

In this case, you need to manually set the text depth of all nodes to the same value. If you set it to text depth=0pt, the text will be aligned as if there were no descenders or subscripts, if you set it to something like text depth=0.25ex, the text in all nodes will be aligned as if there were.

\documentclass{article}
\usepackage[version=3]{mhchem}

\usepackage{tikz}
\usetikzlibrary{shapes}

\newbox\nodebox
\newcommand\mycommand[2]{%
    \begin{tikzpicture}[every node/.append style={text depth=0.25ex}]%
        \node[
            text=#1,
            rectangle,
            inner ysep=4pt,
            inner xsep=2pt,
            rounded corners=7,
            minimum height=5mm,
            minimum width=10mm,
            fill=#1
        ] {\tiny\sffamily \textbf{\ce{#2}}};
        \node[
            yshift=-0.5,
            text=black!95!white
        ] {\scriptsize\sffamily \textbf{\ce{#2}}};
        \node[text=white]{\scriptsize\sffamily\textbf{\ce{#2}}};
    \end{tikzpicture}%
}

\begin{document}

\mycommand{red!40!white}{Al2O3} \mycommand{blue!40!white}{Al}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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