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.

Trying to use siunitx to make my columns look all nice and so such. However, The decimal points are absent...

Example:

Example

Code:

\documentclass[letterpaper,twoside,12pt]{article}

%%% PACKAGES
\usepackage[utf8]{inputenc}
\usepackage{science}
\usepackage{setspace}
    \onehalfspace
\usepackage{graphicx}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{float}
\usepackage{siunitx}
    % \sisetup{group-digits=false,input-symbols={\%}}
\usepackage{amsmath}
\usepackage{natbib}
    \bibpunct{(}{)}{;}{a}{,}{,}
\usepackage{enumerate}
\usepackage{tikz}
    \usetikzlibrary{arrows}


%%% HEADERS & FOOTERS
\usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
\pagestyle{fancy} % options: empty , plain , fancy
\renewcommand{\headrulewidth}{0pt} % customise the layout...

\begin{document}
\begin{body}

\section*{Figures and Tables}
    \begin{figure}
    \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=2.142857142857143cm,y=2.142857142857143cm]
    \draw[-,color=black] (0,0) -- (3.5,0);
    \foreach \x in {,1,2,3}
    \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
    \draw[-,color=black] (0,0) -- (0,3.5);
    \foreach \y in {,1,2,3}
    \draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
    \draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
    \clip(0,0) rectangle (3.5,3.5);
    \draw [shift={(0,0)}] plot[domain=-1.57:1.57,variable=\t]({1*3*cos(\t r)+0*3*sin(\t r)},{0*3*cos(\t r)+1*3*sin(\t r)});
    \draw [shift={(0,0)}] plot[domain=-1.57:1.57,variable=\t]({1*2*cos(\t r)+0*2*sin(\t r)},{0*2*cos(\t r)+1*2*sin(\t r)});
    \draw [shift={(0,0)}] plot[domain=-1.57:1.57,variable=\t]({1*1*cos(\t r)+0*1*sin(\t r)},{0*1*cos(\t r)+1*1*sin(\t r)});
    \draw [dash pattern=on 4pt off 4pt] (0,2)-- (2.24,2);
    \draw [dash pattern=on 4pt off 4pt] (0,1)-- (2.83,1);
    \begin{scriptsize}
    \draw[color=black] (3.11,1.25) node {Best Site};
    \draw[color=black] (1.26,0.64) node {Worst Site};
    \end{scriptsize}
    \end{tikzpicture}
    \caption{A graph of an ideal free distribution}
    \end{figure}

\begin{table}
\caption{A table}
\begin{tabular}{rSSSSS} \toprule
    Amount food in area A:              & {0\%} & {25\%} & {50\%} & {75\%} & {100\%} \\ \midrule
    \multirow{12}{*}{\parbox{7em}{\% Collembolans \\ in area A:}}    & 3.16 & 64.5 & 82.73 & 79 & 90.48 \\
                                        & 1.05 & 64.5 & 80.91 & 74 & 90.48 \\
                                        & 1.05 & 64.5 & 77.27 & 67 & 84.76 \\
                                        & 4 & 8 & 76.36 & 83 & 100 \\
                                        & 3.63 & 5.5 & 71 & 81 & 94 \\
                                        & 2 & 5 & 69 & 80 & 94 \\
                                        & 2 & 5 & 68 & 65 & 84.98 \\
                                        & 0.91 & 4.5 & 15 & 65 & 83.3 \\
                                        & 0 & 4.5    & 10 & 65 & 81.62 \\
                                        & 0 & ~ & 6 & ~ \\
                                        & 0 & ~ & ~ & ~ & ~ \\
                                        & 0 & ~ & ~ & ~ & ~ \\ \midrule
            Average:                    & {89\%} & {73\%} & {56\%} & {25\%} & {1\%}

\end{tabular}
\end{table}

\end{body}
\end{document}

Bonus points if you can tell me how to fix:

  • Why when I put the above in a \begin{table} it disappears
  • How I can split the multirow into 2 lines rather than stretching it out
share|improve this question
    
The "disappearance" problem is caused by the \body environment, which is defined by the science package. It uses multicol to set the body in two columns, and floats are disallowed in multicols environments. Unless you really need the science package for some specific requirement you probably shouldn't use it. –  Alan Munn Nov 21 '11 at 0:04
add comment

1 Answer

up vote 6 down vote accepted

You probably want S columns. To load the package, use \usepackage{siunitx}, not the mix of lower and upper case you used. One way of splitting the multirow in 2 lines is to use a \parbox.

\documentclass{article}
\usepackage{siunitx}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}
\begin{table}
\caption{A table}
\begin{tabular}{rSSSSS} \toprule
    Amount food in area A:              & {0\%} & {25\%} & {50\%} & {75\%} & {100\%} \\ \midrule
    \multirow{12}{*}{\parbox{7em}{\% Collembolans \\ in area A:}}    & 3.16 & 64.5 & 82.73 & 79 & 90.48 \\
                                        & 1.05 & 64.5 & 80.91 & 74 & 90.48 \\
                                        & 1.05 & 64.5 & 77.27 & 67 & 84.76 \\
                                        & 4 & 8 & 76.36 & 83 & 100 \\
                                        & 3.63 & 5.5 & 71 & 81 & 94 \\
                                        & 2 & 5 & 69 & 80 & 94 \\
                                        & 2 & 5 & 68 & 65 & 84.98 \\
                                        & 0.91 & 4.5 & 15 & 65 & 83.3 \\
                                        & 0 & 4.5    & 10 & 65 & 81.62 \\
                                        & 0 & ~ & 6 & ~ \\
                                        & 0 & ~ & ~ & ~ & ~ \\
                                        & 0 & ~ & ~ & ~ & ~ \\ \midrule
            Average:                    & {89\%} & {73\%} & {56\%} & {25\%} & {1\%}

\end{tabular}
\end{table}
\end{document}

enter image description here

The reason tables and figures disappear, is the body environment from the science package. This is defined as

\newenvironment{body}{\vspace{1pc}\begin{multicols}{2}}{\end{multicols}}

so it's basically a multicols environment with some space above it. Floats are not allowed in multicols. You could replace the figure/table environment with the center environment, load the caption package, and use \captionof{figure}{A figure} (replace figure with table for a table caption). However, your table is really too wide for a single column, so either use the table* environment which spans both columns, or make the table narrower, e.g. with Alan Munns suggestion.

share|improve this answer
    
Alternatively you could make the first column >{\centering}p{1in} and then use {1in} instead of {*} for the \multirow specification. This would make the first column narrower altogether. –  Alan Munn Nov 20 '11 at 22:31
    
You may want to add the command \sisetup{group-digits=false,input-symbols={\%}} in the preamble to avoid getting an unwanted separation between the numbers and the % sign in the header line and the final line. –  Mico Nov 20 '11 at 22:37
    
@Mico Didn't notice that actually. However, your fix causes the zero in 0% to disappear. Would one want the percent values to be aligned anyway? May be better to enclose all of them in braces instead. –  Torbjørn T. Nov 20 '11 at 22:44
    
Great! Thanks. Putting it in a \begin{table} still makes it disappear though. Any clue why? –  Zak Nov 20 '11 at 23:07
    
@Zak No, I think you would have to make an minimal working example (MWE), as my example above works just fine. –  Torbjørn T. Nov 20 '11 at 23:09
show 7 more comments

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.