Math & ScienceMultiline Underset

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Multiline Underset

Post by ghostanime2001 »

How can I mimick the substack command in mathematical formula except this time for chemical formula?
Last edited by ghostanime2001 on Fri Aug 26, 2011 7:55 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: writing stuff underneath a chemical formula

Post by Stefan Kottwitz »

I guess you can use \substack for chemical formulas as well, depending on how they are written.

Stefan
LaTeX.org admin
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: writing stuff underneath a chemical formula

Post by ghostanime2001 »

I tried using substack except the things I wanted underneath the chemical formula were set as subscripts instead :shock:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: writing stuff underneath a chemical formula

Post by Stefan Kottwitz »

How should we help you if you don't tell what you are doing? If you don't show a code example? If I write chemical equations with standard or amsmath tools, of course I can use \substack. You did not tell that you use a chemistry package such as mhchem, possibly.

Stefan
LaTeX.org admin
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: writing stuff underneath a chemical formula

Post by ghostanime2001 »

Yes I am using mhchem to write my formula then using amsmath (\substack command) with chemical formula typset using mhchem
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: writing stuff underneath a chemical formula

Post by Stefan Kottwitz »

Well, it's still theoretic. If you would have posted an example formula, I would have worked on it. I am not using mhchem myself and I will not work out an example myself just because it saves you time not to copy your example here in. Perhaps somebody else does. I'm off for today, as it's late.

Stefan
LaTeX.org admin
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Multiline Underset

Post by ghostanime2001 »

I'm sort of close. Except I need to put more lines below "4.5 g". Here is my code:

Code: Select all

\documentclass{article}
\usepackage{amsmath}   
\usepackage[version=3]{mhchem}  
\begin{document}
\ce{2Al + $\underset{\text{4.5 g}}{\ce{Zn(OH)2}}$ -> Al2(SO4)3 + 3H2}
\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Multiline Underset

Post by Stefan Kottwitz »

You could use array, tabular, \substack, subarray, \parbox and more.

Here's a tabular example:

Code: Select all

\documentclass{article}
\usepackage{amsmath}   
\usepackage[version=3]{mhchem} 
\begin{document}
\ce{2Al + $\underset{\text{\begin{tabular}{c}4.5 g\\[-1ex]more\end{tabular}}}{\ce{Zn(OH)2}}$ -> Al2(SO4)3 + 3H2}
\end{document}
If it should be math, omit \text and use array, subarray or \substack.

Stefan
LaTeX.org admin
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Multiline Underset

Post by ghostanime2001 »

Is this what you mean by using 'array' ?

Code: Select all

\documentclass{article}
    \usepackage{amsmath}   
    \usepackage[version=3]{mhchem}
    \begin{document}
    \ce{2Al + $\underset{\begin{array}{c}4.5 g\\98.1 g/mol\\more\\more\end{array}}{\ce{Zn(OH)2}}$ -> Al2(SO4)3 + 3H2}
    \end{document}
Also, is this what you mean by 'subarray' ?

Code: Select all

    \documentclass{article}
    \usepackage{amsmath}   
    \usepackage[version=3]{mhchem}
    \begin{document}
    \ce{2Al + $\underset{\begin{subarray}{c}4.5 g\\98.1 g/mol\\Top shelf\\more\end{subarray}}{\ce{Zn(OH)2}}$ -> Al2(SO4)3 + 3H2}
    \end{document}
Is this what you mean by 'substack' ?

Code: Select all

    \documentclass{article}
    \usepackage{amsmath}   
    \usepackage[version=3]{mhchem}
    \begin{document}
    \ce{2Al + $\underset{\substack{\begin{subarray}{c}4.5 g\\98.1 g/mol\\Top shelf\\more\end{subarray}}}{\ce{Zn(OH)2}}$ -> Al2(SO4)3 + 3H2}
    \end{document}
Is this what you mean by using '\parbox' ?

Code: Select all

    \documentclass{article}
    \usepackage{amsmath}   
    \usepackage[version=3]{mhchem}
    \begin{document}
    \ce{2Al + $\underset{\parbox[c]{3cm}{4.5 g\\98.1 g/mol$^-$}}{\ce{Zn(OH)2}}$ -> Al2(SO4)3 + 3H2}
    \end{document}
I am showing you all of these because I do not want to get my code wrong and knowing that I have done something wrong but in fact there was some other way that you recommended. So that's why I am showing you.

Also, what are the 'more' in your previous post? I am hoping they are something I am indeed looking for rather than these. I want to make my selection based on everything I test.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Multiline Underset

Post by Stefan Kottwitz »

It it similar to what I meant. Those examples work, however it's important to know when to use math mode and when text mode. We can see that text is incorrectly used in math mode when it's italic and spacing is strange.

I mentioned those possibilities in order to say that there are usually many ways, of which we could choose the best.
  • A simple `\parbox` would be a good choice for (possibly justified) muliline text.
  • A minipage would work similar (that's for example meant by 'more' ealier).
  • tabular would be good if you need alignment (centered, right or left) and if the content should be in text mode.
  • array would also be good for aligned multiline content, which is mainly maths.
  • \substack is a handy tool exactly for multiline subscripts which are centered to each other.
  • The subarray environment is like \substack but is an environment and allows left alignment.
The best choice depends on the content and the desired layout. Since you just said
I need to put more lines below "4.5 g"
it wasn't possible to recommend one, so I just could list some for you to check out.

Stefan
LaTeX.org admin
Post Reply