# How to format an entire column in math mode using \mathrm

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}

• Can you add a couple of rows of the table, just to play with what you already have? – egreg Sep 1 '17 at 17:44
• don't tell anyone but you can use >{$\rm}c<{$} although now you have added an example it looks like one of the chemistry package macros might be more suitable than bare math mode – David Carlisle Sep 1 '17 at 17:49
• @egreg I posted the MWE – Daniel Valencia C. Sep 1 '17 at 17:51
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – user36296 Sep 26 '17 at 16:38

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 \\
B & KH2PO4 & 8,700 \\
& Na2HPO4 & 7,060 \\
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 \\
D & EDTA\cdot Na2 & 18,600 \\
\midrule
\end{tabular}

\end{document}


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

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.