Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Here is a table with the siunitx S column type. I would like the italic value (the command with swapshift) to be still centered on the decimal point. The superscript can be variable, but will almost always be just "a" or "b", maybe "c", never more than 1 letter in length.

\documentclass{memoir}
\usepackage{siunitx}
\usepackage{multirow}
\sisetup{inter-unit-product={}\cdot{},sticky-per=true,multi-part-units=single,separate-uncertainty=true,list-units=single,range-units=single,detect-all,detect-weight=true,detect-inline-weight=math}
\usepackage{etoolbox}
\newcommand{\thirteenc}{\textsuperscript{13}C}
\newcommand{\oneh}{\textsuperscript{1}H}
\robustify\bfseries
\usepackage{bpchem}
\usepackage[tracking=bpchem]{chemstyle}
\setcounter{BPCno}{200}

\newcommand{\mcol}[3]{\multicolumn{#1}{#2}{#3}}
\newcommand{\mrow}[3]{\multirow{#1}{#2}{#3}}
\newcommand{\onemultcol}[2]{\mcol{1}{#1}{#2}}
\newcolumntype{g}{>{\rule{1.2em}{0em}}r@{ }l}
\newcommand{\greek}[1]{$#1$}
\newcommand{\range}[1]{\mcol{1}{c}{\bfseries #1}}
\newcommand{\swapshift}[2]{\mcol{1}{c}{\textit{#1}\textsuperscript{#2}}}
\newenvironment{onehTable}[2]{%
\begin{tabular}{gS[table-format=1.2]S[table-format=1.2]S[table-format=1.2]S[table-format=1.2]} \toprule%
\mcol{2}{c}{\mrow{2}{*}{Position}} & \mcol{2}{c}{Computed} & \mcol{2}{c}{Experimental} \\%
& & \mcol{1}{c}{\textbf{#1}} & \mcol{1}{c}{\textbf{#2}} & \mcol{1}{c}{\textbf{#1}} & \mcol{1}{c}{\textbf{#2}} \\%
\cmidrule[\lightrulewidth](r){1-2} \cmidrule[\lightrulewidth](lr){3-4} \cmidrule[\lightrulewidth](l){5-6}}%
{\end{tabular}}

\begin{document}
\CNlabelsubnoref{carvomenthone}{cis}
\CNlabelsubnoref{carvomenthone}{trans}
\begin{table}
    \centering
    \caption{Calculated and Experimental \oneh{} Shifts (in ppm) for carvomenthones \CNref{carvomenthone}}\label{tab:SI:carvomenthone1H}
    \begin{onehTable}{\CNrefsub{carvomenthone}{cis}}{\CNrefsub{carvomenthone}{trans}}
    2 & & 2.47 & 2.48 & 2.45 & 2.33 \\
    3 & \greek{\alpha} & 1.87 & 1.29 & \swapshift{1.87}{a} & 1.30 \\
    3 & \greek{\beta} & 1.70 & 2.12 & \range{1.60--1.75} & 2.10 \\
    10 & Me & 1.06 & 0.92 & 1.10 & \swapshift{1.01}{b} \\ \bottomrule
    \end{onehTable}
\end{table}
\end{document}
share|improve this question
    
With this data you could use \newcommand{\swapshift}[2]{\mcol{1}{c}{\kern0.1em\textit{#1}\rlap{\textsuperscr‌​ipt{#2}}}}, but that won't work with all range of numerical data. Not sure if there is a proper way to eliminate the \kern0.1em fudge factor, but that was required since this text is in italics. –  Peter Grill Sep 5 '12 at 4:29
    
@PeterGrill Sorry, I keep getting an Undefined control sequence,<argument> \textsuperscript{a}... error now with that updated swapshift command. –  J M Sep 5 '12 at 6:16
add comment

1 Answer

up vote 2 down vote accepted

Simplifying your example a bit, I think you want something like

\documentclass{article}
\usepackage{booktabs,etoolbox,multirow,siunitx}
\robustify\itshape
\begin{document}
\begin{table}
  \sisetup{table-format = 1.2, detect-all}
  \begin{tabular}
    {
      >{\rule{1.2em}{0em}}
      r@{ }
      l
      S
      S
      S[table-space-text-post = \textsuperscript{a}]
      S[table-space-text-post = \textsuperscript{b}]
    }
    \toprule
      \multicolumn{2}{c}{\multirow{2}{*}{Position}} &
        \multicolumn{2}{c}{Computed} &
        \multicolumn{2}{c}{Experimental} \\
       & &
         {\textbf{201a}} & {\textbf{201b}} & {\textbf{201a}} & {\textbf{201b}} \\
       \cmidrule[\lightrulewidth](r){1-2}
         \cmidrule[\lightrulewidth](lr){3-4}
         \cmidrule[\lightrulewidth](l){5-6}
       2 &          & 2.47 & 2.48 &         2.45                       & 2.33 \\
       3 & $\alpha$ & 1.87 & 1.29 & \itshape 1.87{\textsuperscript{a}} & 1.30 \\
       3 & $\beta$  & 1.70 & 2.12 & {\bfseries 1.60--1.75}             & 2.10 \\
      10 & Me       & 1.06 & 0.92 &         1.10                      &
        \itshape 1.01{\textsuperscript{b}} \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

The key here is to use \itshape to alter the formatting while retaining siunitx S column alignment, plus setting up so space for the superscript using table-space-text-post.

I've also cut down on the use of \multicolumn, as {...} will escape thing from siunitx more clearly. siunitx treats anything inside a wrapping set of braces as 'text', so for example

& {\bfseries 1.60--1.75} &

typesets the material without parsing the number: the alignment of 'text' is governed by the table-text-alignment key. (You could alternatively use \multicolumn and \tablenum, but that seems overly complex here.)

The table-space-text-post setting reserves 'some space' for additional material after the number. It needs to be wide enough when typeset to hold the largest item you will have after the text in a column. Usually, this is simply a case of picking something representative, although if the letter width varies a lot in your font then that may be an issue. I've used superscript a and b as they are the only things in those columns: I guess if you have an m or w to fit in you'll need to use them as they are wider!

share|improve this answer
    
Ah wonderful! Can you explain your comment about the multicolumn and the {...} what is the {...}? Also, is there a way to use use the table-space-text-post for more than one possibility? I have one particularly nasty NMR spectra that requires superscripts up to the letter g in one column. –  J M Sep 5 '12 at 7:09
    
Thank you so much for the added explanation, definitely help me understand better! I've implemented it into my thesis, and it works great. –  J M Sep 5 '12 at 16:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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