3

I have a tabular table with all elements left-justified. Here is the MWE code followed by the output:

\documentclass{article}

\begin{document}

\begin{table}
\begin{tabular}{lll}
  \toprule
  & $\alpha$ & $\beta$\\
  \midrule
  atomic $\text{C}$ & 1.1 & 2.2\\
  ($\text{C}_a$) & & \\ \addlinespace
  polymeric $\text{C}$ & 3.3 & 4.4\\
  ($\text{C}_p$) & & \\
  \bottomrule
\end{tabular}
\end{table}

\end{document}

table

  • I would like to align the C in C_a with the the C in "atomic C".
  • I would also like to align the C in C_p with the C in "polymeric C".

In other words, indent C_a and C_b so that they align with the C immediately above.

Is this possible in a relatively simple way?

(In actuality, I am using the chemmacros package to typeset the C's (e.g., \ch{C}), but to keep things simple in my MWE, I used \text. I think that the answer to this question, if one exists, will probably be independent of whether I use \ch or \text.)

  • Please make your example code compilable by adding the missing packages. Regarding your use of \text instead of \ch in your MWE: To be honest, I don't think, using \text for simplicity really helps here. For \text you need to load amsmath, for \ch, you also just need one package, so I can't realls see the simplicity here. – leandriis Oct 19 at 18:25
3

Here's a solution that employs the \mathllap macro of the mathtools package, which is a superset of the amsmath package, to facilitate the alignment of the \ch{C} elements.

enter image description here

\documentclass{article}
\usepackage{chemmacros,booktabs,mathtools}
\newcommand\myarray[2]{%
   $\begin{array}[t]{@{}l@{}} #1 \\ \mathllap{(}#2) \end{array}$}
\begin{document}
 
\begin{table}
\centering
\begin{tabular}{@{}lcc@{}}
  \toprule
  & $\alpha$ & $\beta$\\
  \midrule
  atomic \myarray{\ch{C}}{\ch{C}_a} & 1.1 & 2.2\\
  \addlinespace
  polymeric \myarray{\ch{C}}{\ch{C}_p} & 3.3 & 4.4\\
  \bottomrule
\end{tabular}
\end{table}

\end{document}
| improve this answer | |
2

enter image description here

Here is a method using \widthof from the calc package in order to measure the required indentation:

\documentclass{article}
\usepackage{booktabs}
\usepackage{chemmacros}
\usepackage{calc}

\newlength{\mylengthatomic}
\setlength{\mylengthatomic}{\widthof{atomic}-\widthof{(}}
\newlength{\mylengthpolymeric}
\setlength{\mylengthpolymeric}{\widthof{polymeric}-\widthof{(}}
\begin{document}

\begin{table}
\begin{tabular}{lll}
  \toprule
  & $\alpha$ & $\beta$\\
  \midrule
  atomic \ch{C}  & 1.1 & 2.2\\
  \hspace{\mylengthatomic} (\ch{C_a}) & & \\ \addlinespace
  polymeric \ch{C} & 3.3 & 4.4\\
  \hspace{\mylengthpolymeric} (\ch{C_p}) & & \\
  \bottomrule
\end{tabular}
\end{table}

\end{document}

The second example uses nested tabulars for the alignment:

\documentclass{article}
\usepackage{booktabs}
\usepackage{chemmacros}


\begin{table}
\begin{tabular}{lll}
  \toprule
  & $\alpha$ & $\beta$\\
  \midrule
  \setlength{\tabcolsep}{0pt}\begin{tabular}[t]{ll} atomic & \phantom{(}\ch{C} \\ & (\ch{C_a})\end{tabular}  & 1.1 & 2.2\\ \addlinespace
  \setlength{\tabcolsep}{0pt}\begin{tabular}[t]{ll} polymeric & \phantom{(}\ch{C} \\ & (\ch{C_p})\end{tabular} & 3.3 & 4.4\\
  \bottomrule
\end{tabular}
\end{table}

\end{document}
| 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.