2

I want to create commands that will show some data and will be used as a single character in different places (paragraphs, tables etc.).

Here is an example of how it should be looking: enter image description here

I achieved it with the following code:

\newcommand{\Helium}{
    \begin{tabular}{|c|}
        {\huge He}\\
        {\small Helium}
    \end{tabular}
}

\newcommand{\Titanium}{
    \begin{tabular}{|c|}
        {\huge Ti}\\
        {\small Titanium}
    \end{tabular}
}

And now it is used as:

Some text \Helium{} and more text \Titanium{} and final text.
  1. Is it good to use tables for that (side lines are not needed and are here only to show size of the created element)?
  2. Is there any way to reduce padding? Horizontal padding is quite big and when side lines are removed it takes too much space.
1
  • 1
    Welcome to TeX.SX! Replace {|c||} with {@{}c@{}} the remove the space on each side of the column.
    – jlab
    Commented Jul 3 at 17:38

1 Answer 1

3

Define a helper command that avoids code duplication and ensures uniformity. If you change your mind and want, say \large instead of \Huge, you can just modify one definition.

Be careful with line endings in definition! I protected two of them with % so as they don't produce unwanted spaces in putput.

With \begin{tabular}[t] the chemical symbol is aligned with the text.

\documentclass{article}

\newcommand{\chemicalelement}[2]{% <--- important %
  \begin{tabular}[t]{@{}c@{}}
    \huge #1\\
    \small #2
  \end{tabular}% <--- important %
}
\newcommand{\Helium}{\chemicalelement{He}{Helium}}
\newcommand{\Titanium}{\chemicalelement{Ti}{Titanium}}

\begin{document}

Some text \Helium{} and more text \Titanium{} and final text.

\end{document}

enter image description here

2
  • Yes, it looks now just as I wanted. And I was thinking about creating one command. Just didn't thought about 2 arguments. Thanks for the help! Do you think that using tables is good here? I was thinking there could be some other way like boxes, but it seems that \vbox and \hbox are for other purposes.
    – Taras
    Commented Jul 3 at 18:48
  • 1
    @Taras \vtop would allow more control on the vertical spacing between the two parts.
    – egreg
    Commented Jul 3 at 19:17

You must log in to answer this question.

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