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.

I have a table with decimal numbers aligned at decimal point. In the column header, I have a % sign. In the code snippet given below, the percent sign is aligned at the left in the column, but I would like it to be either aligning with the decimal points or to the right. How can I achieve this?

Current result:

enter image description here

\documentclass[ngerman]{scrbook}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{l S[table-format=3.2]}
    \textbf{fruit} & \textbf{\%} \\
    apple   & 12,34 \\
    banana  & ,1 \\
    cherry  & 1,2345 \\
    coconut & 100 \\
\end{tabular}

\end{document}
share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

You can align to the right by using multicolumn:

\documentclass[ngerman]{scrbook}
\usepackage{siunitx}

\begin{document}

\begin{tabular}{l S[table-format=3.4]}
    \textbf{fruit} & \multicolumn{1}{r}{\textbf{\%}} \\         %  
    apple   & 12,34 \\
    banana  & ,1 \\
    cherry  & 1,2345 \\
    coconut & 100 \\
\end{tabular}

\end{document}

I have changed S[table-format=3.2] to S[table-format=3.4] so as to compensate for the entry in cherry..

enter image description here

share|improve this answer
add comment

To center the % symbol in the header row of the second column, you could encase the instruction \textbf{\%} in curly braces, like this:

{\textbf{\%}}

Using \multicolumn{1}{c}{\textbf{\%}} works too...

share|improve this answer
    
This would only center the symbol over the whole column width, but not aligning it at the decimal point. –  Martin Jul 31 '13 at 9:51
    
@Martin - In the present case, i.e., given the OP's data for the various percentages, centering the % symbols works out to being pretty much the same as aligning it directly on the decimal point. :-) –  Mico Jul 31 '13 at 10:00
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.