4

I'm making a table with a column full of equations. To avoid the repetitive usage of $\mathrm{equation}$ in each row, I used \begin{tabular}{>{$}c<{$}} and it works perfectly, however, I'd like to use the command \mathrm avoiding the italic format. How can I include the \mathrm in the entire column format?

EDIT 1:

A MWE

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker = {,}}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{c>{$}c<{$}S}
\midrule
\textbf{Solution} & \textbf{Chemicals} & \textbf{Concentration (mg/mL)} \\
\midrule
A & NaNO_{3} & 8,500 \\
& MgSO_{4}\cdot7H_{2}O & 2,450 \\
& MgCl_{2}\cdot6H_{2}O & 2,050 \\
& CaCl_{2}\cdot2H_{2}O & 1,450 \\
\\
B & KH_{2}PO_{4} & 8,700 \\
& Na_{2}HPO_{4} & 7,060 \\
\\
C & H_{3}BO_{3} & 24,800 \\
& MnCl_{2}\cdot4H_{2}O & 13,900 \\
& FeCl_{3}\cdot6H_{2}O & 10,800 \\
& ZnCl_{2} & 3,350 \\
& CoCl_{2}\cdot6H_{2}O & 0,190 \\
& CuCl_{2} & 0,011 \\
\\
D & EDTA\cdot Na_{2} & 18,600 \\
\midrule
\end{tabular}%
\end{document}
8

Use a specialized package for chemistry, for instance mhchem, that also eases input. Together with collcell you get what you want.

\documentclass{article}
\usepackage{booktabs}
\usepackage[version=4]{mhchem}
\usepackage{collcell}
\usepackage{siunitx}

\sisetup{
  output-decimal-marker = {,},
  per-mode=symbol,
}

\begin{document}

\begin{tabular}{
  c
  >{\collectcell\ce}c<{\endcollectcell}
  S[table-format=2.3]
}
\midrule
\textbf{Solution} & \multicolumn{1}{c}{\textbf{Chemicals}} & {\textbf{Concentration}} \\
&& {(\si{\milli\gram\per\milli\liter})} \\
\midrule
A & NaNO3 & 8,500 \\
  & MgSO4 . 7 H_{2}O & 2,450 \\
  & MgCl2 . 6 H_{2}O & 2,050 \\
  & CaCl2 . 2 H_{2}O & 1,450 \\
\addlinespace
B & KH2PO4 & 8,700 \\
  & Na2HPO4 & 7,060 \\
\addlinespace
C & H3BO3 & 24,800 \\
  & MnCl2 . 4 H_{2}O & 13,900 \\
  & FeCl3 . 6 H_{2}O & 10,800 \\
  & ZnCl2 & 3,350 \\
  & CoCl2 . 6 H_{2}O & 0,190 \\
  & CuCl2 & 0,011 \\
\addlinespace
D & EDTA\cdot Na2 & 18,600 \\
\midrule
\end{tabular}

\end{document}

enter image description here

| improve this answer | |
  • Hi egreg how are you? +1 for you excellent work. – Sebastiano Sep 1 '17 at 20:01
6

You can use collcell for it.

\documentclass[]{article}

\usepackage{array}
\usepackage{collcell}

\newcommand*{\mymathrm}[1]{$\mathrm{#1}$}

\begin{document}
\begin{tabular}[]{>{\collectcell\mymathrm}c<{\endcollectcell}}
    E = mc^2\\
    E = hf
\end{tabular}
\end{document}

You can change the definition of \mymathrm to anything that accepts one argument, including a chemistry macro.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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