Math & ScienceUsing tabular/array with chemical equations

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

Using tabular/array with chemical equations

Post by ghostanime2001 »

How can I set the plus signs and right arrow on the last line align between the masses (46 g + 36 g --> 80 g + 2 g) AND align vertically with the plus and right arrow on the first line? This is the closest to what I can get please see the latex code... And yes this is my minimal example believe me.. I've got a huge table with many more equations.

Code: Select all

\documentclass[fleqn]{article}
\usepackage{amsmath}   
\usepackage[version=3]{mhchem}
\usepackage{chemmacros}
\begin{document}
$\begin{tabular}[t]{@{}lllllllll}
\ce{$\underset{\begin{tabular}{@{}c@{}}2 molecules \\ 2 mols \\ 2(23) \\ 46g\end{tabular}}{\ce{2Na_{(s)}}}$}&+&\ce{$\underset{\begin{tabular}{@{}c@{}}2 molecules \\ 2 mols \\ 2(18) \\ 36g\end{tabular}}{\ce{2H2O_{(l)}}}$}&\ce{->}&\ce{$\underset{\begin{tabular}{@{}c@{}}2 molecules \\ 2 mols \\ 2(40) \\ 80g\end{tabular}}{\ce{2NaOH_{(aq)}}}$}&+&\ce{$\underset{\begin{tabular}{@{}c@{}}1 molecule \\ 1 mol \\ 2 \\ 2g\end{tabular}}{\ce{H2\gas{}}}$} \\
&+&&\ce{->}&&+&
\end{tabular}$
\end{document}

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Using tabular/array with chemical equations

Post by ghostanime2001 »

Anyone?
User avatar
justdeath
Posts: 69
Joined: Mon Sep 05, 2011 10:27 am

Using tabular/array with chemical equations

Post by justdeath »

You write tabular a little strangely. Here is my tabular:

Code: Select all

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

\begin{document}
\begin{tabular}{*{7}{c}}
\ce{2 Na_{(s)}} & + & \ce{2H2O_{(l)}} & $\longrightarrow$ & \ce{2NaOH_{(aq)}} & + & \ce{H2\gas{}} \\
2 molecules & & 2 molecules & & 2 molecules & & 1 molecule \\
2 mols & & 2 mols & & 2 mols & & 1 mol \\
2(18) & & 2(22) & & 2(40) & & 2 \\
46g & + & 36g & $\longrightarrow$ & 80g & + & 2g
\end{tabular}
\end{document}
Nikolay
Last edited by justdeath on Thu Sep 22, 2011 11:22 pm, edited 1 time in total.
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Using tabular/array with chemical equations

Post by ghostanime2001 »

I'd like to keep the \underset and tabular environment in my code. I am looking for minor tweak if there is one which will allow me to do what you did.
User avatar
justdeath
Posts: 69
Joined: Mon Sep 05, 2011 10:27 am

Using tabular/array with chemical equations

Post by justdeath »

This is the closest I can get:

Code: Select all

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

\begin{document}
$\begin{tabular}[t]{@{}lllllllll}
\ce{$\underset{\begin{tabular}{@{}c@{}}2 molecules \\ 2 mols \\ 2(23) \\ 46g\end{tabular}}{\ce{2Na_{(s)}}}$}&
\ce{$\underset{\begin{tabular}{@{}c@{}} \\ \\ \\ + \end{tabular}}+$}&
\ce{$\underset{\begin{tabular}{@{}c@{}}2 molecules \\ 2 mols \\ 2(18) \\ 36g\end{tabular}}{\ce{2H2O_{(l)}}}$}&
\ce{$\underset{\begin{tabular}{@{}c@{}} \\ \\ \\ $\longrightarrow$ \end{tabular}}\longrightarrow$}&
\ce{$\underset{\begin{tabular}{@{}c@{}}2 molecules \\ 2 mols \\ 2(40) \\ 80g\end{tabular}}{\ce{2NaOH_{(aq)}}}$}&
\ce{$\underset{\begin{tabular}{@{}c@{}} \\ \\ \\ + \end{tabular}}+$}&
\ce{$\underset{\begin{tabular}{@{}c@{}}1 molecule \\ 1 mol \\ 2 \\ 2g\end{tabular}}{\ce{H2\gas{}}}$}
\end{tabular}$
\end{document}
And the signs on the last row are aligned vertically, but not horizontally (with the masses).

Nikolay
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Using tabular/array with chemical equations

Post by ghostanime2001 »

hmmmm.... no sorry wasn't what I was looking for exactly.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Using tabular/array with chemical equations

Post by cgnieder »

Hi,

I don't understand, why you want to keep the \underset command and the tabular environment?

Otherwise I would propose you use the possibilities which the chemmacros package offers, seeing that you are using it already.

Code: Select all

\documentclass[fleqn]{article}
\usepackage{amsmath}   
\usepackage[version=3]{mhchem}
\usepackage{chemmacros,siunitx}

\begin{document}
\newreaction*+{reactionsat}{alignat}

\begin{reactionsat*}{6}
 & 2 Na\solid{}   && {}  + 2 H2O\liquid{} && -> && 2 NaOH\aq{}    && {}  + H2\gas{} \\
 & 2 molecules    && \quad{} 2 molecules  &&    && 2 molecules    && \quad{} 1 molecule \\
 & \SI{2}{\mole}  && \quad \SI{2}{\mole}  &&    && \SI{2}{\mole}  && \quad \SI{1}{\mole} \\
 & \text{2(23)}   && \quad \text{2(18)}   &&    && \text{2(40)}   && \quad 2 \\
 & \SI{46}{\gram} && {}  + \SI{36}{\gram} && -> && \SI{80}{\gram} && {}  + \SI{2}{\gram}
\end{reactionsat*}

\end{document}
test.jpg
test.jpg (14.14 KiB) Viewed 8212 times
Regards
site moderator & package author
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Using tabular/array with chemical equations

Post by ghostanime2001 »

They are used because of the spacing between the chemical formulas the first line of text beneath it
Post Reply