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 converted from excel. I want to transform the numbers in the table to the math mode, i.e., 15 -> $15$. Is there any visual way I can use it. I am using TexStudio.

CODE:

\begin{table}[htbp]
  \centering
  \caption{Comparison of microaggregation algorithms to protect different datasets for $k=\{3,4,\ldots,10\}$}
    \begin{tabular}{cr|rrrrrrrrc}
    \multirow{2}[1]{*}{Dataset} & \multicolumn{1}{c|}{\multirow{2}[1]{*}{Method}} & \multicolumn{8}{c}{Information Loss (\%)}                     & \multirow{2}[1]{*}{Elapsed time (sec)} \\
          & \multicolumn{1}{c|}{} & $k=3$   & $k=4$   & $k=5$   & $k=6$   & $k=7$   & $k=8$   & $k=9$   & $k=10$  &  \\
    \hline
    \multirow{3}[1]{*}{\dataset{Tarragona}}  & KD-CBFS & 16.9500 & 19.7700 & 22.8900 & 26.4100 & 28.2600 & 29.3100 & 31.6200 & 33.2600 & $<1$ \\
          & V-MDAV & 16.9507 & 19.7695 & 22.8867 & 26.4131 & 28.2616 & 29.3119 & 31.6184 & 33.2601 & $<1$ \\
          & FDM   & 15.8548 & 17.8439 & 22.6442 & 25.1970 & 27.7465 & 28.9472 & 30.0313 & 32.8549 & $<1$ \\ \hline
    \multirow{3}[0]{*}{\dataset{Census}} & KD-CBFS & 5.6620 & 7.5140 & 9.0070 & 10.3654 & 11.6688 & 12.3068 & 13.3368 & 14.0730 & $<1$ \\
          & V-MDAV & 5.6620 & 7.5140 & 9.0070 & 10.3654 & 11.6688 & 12.3068 & 13.3368 & 14.0730 & $<1$ \\ 
          & FDM   & 5.3828 & 7.0645 & 8.7178 & 10.1436 & 11.3940 & 12.6727 & 13.7732 & 14.7735 & $<1$ \\ \hline
    \multirow{3}[0]{*}{\dataset{EIA}} & KD-CBFS & 0.4883 & 0.6727 & 1.7764 & 1.3157 & 2.2141 & 2.9910 & 3.4086 & 3.5474 & $<1$ \\
          & V-MDAV & 0.4884 & 0.6718 & 1.7693 & 1.3157 & 2.2081 & 2.9917 & 3.4086 & 3.5474 & $1$ \\ 
          & FDM   & 0.4808 & 0.7311 & 1.0678 & 1.3533 & 1.7343 & 1.9019 & 2.0491 & 2.1674 & $<1$ \\ \hline
    \multirow{3}[0]{*}{\dataset{Income}} & KD-CBFS & 0.675015 & 0.928399 & 1.19127 & 1.4107 & 1.58581 & 1.80879 & 1.94347 & 2.12738 & $1$ \\ 
          & V-MDAV & 0.655816 & 0.928362 & 1.19121 & 1.41074 & 1.58681 & 1.80878 & 1.94346 & 2.12738 & $90$ \\
          & FDM   & 0.593726 & 0.838746 & 1.0747 & 1.30892 & 1.5398 & 1.75383 & 1.95588 & 2.15949 & $1$ \\ \hline
    \multirow{3}[0]{*}{\dataset{Forest}} & KD-CBFS & 0.494946 & 0.703865 & 0.885494 & 1.05023 & 1.20079 & 1.33881 & 1.46986 & 1.59104 & $67$ \\
          & V-MDAV &       &       &       &       &       &       &       &       & $>3600$ \\
          & FDM   & 0.426531 & 0.608566 & 0.782772 & 0.952619 & 1.11867 & 1.28177 & 1.44231 & 1.59784 & $65$ \\ \hline
    \end{tabular}%
  \label{tab:results1}%
\end{table}%
share|improve this question
    
Use the “Align Column” function of TeXstudio and then block select right before the first column of numbers and add $ where you need it. Or: Change the column specifications to >{$}r<{$} (and remove the $ in the header and/or use \multicolumn). Or: Use siunitx. –  Qrrbrbirlbel Sep 21 '13 at 16:04
    
You will need to \usepackage{array} to enable the >{$}r<{$} mark up. –  Thruston Sep 21 '13 at 16:13

1 Answer 1

up vote 6 down vote accepted

I would use the siunitx package for this table, which avoids the issue.

You'll notice that I have used S[table-format=2.5] to mean that there are at most 2 numbers before the decimal, and 5 numbers after it.

screenshot

I wasn't sure what the dataset command was supposed to do- you'll need to change it appropriately.

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{multirow}
\usepackage[landscape]{geometry}
\usepackage{siunitx}
\newcommand{\dataset}[1]{#1}

\begin{document}
\begin{table}[htbp]
    \centering
    \caption{Comparison of microaggregation algorithms to protect different datasets for $k=\{3,4,\ldots,10\}$}
    \begin{tabular}{cr|S[table-format=2.6]S[table-format=2.6]S[table-format=2.6]S[table-format=2.6]S[table-format=2.5]S[table-format=2.5]S[table-format=2.5]S[table-format=2.5]S[table-comparator=true]}
        \multirow{2}[1]{*}{Dataset} & \multicolumn{1}{c|}{\multirow{2}[1]{*}{Method}} & \multicolumn{8}{c}{Information Loss (\%)}                     & \multirow{2}[1]{*}{Elapsed time (sec)} \\
        & \multicolumn{1}{c|}{} & {$k=3$}  & {$k=4$}  & {$k=5$}  & {$k=6$}  & {$k=7$} & {$k=8$} & {$k=9$}   & {$k=10$}  &         \\
        \hline
        \multirow{3}[1]{*}{\dataset{Tarragona}} & KD-CBFS               & 16.9500  & 19.7700  & 22.8900  & 26.4100  & 28.2600 & 29.3100 & 31.6200 & 33.2600 & <1    \\
                                                & V-MDAV                & 16.9507  & 19.7695  & 22.8867  & 26.4131  & 28.2616 & 29.3119 & 31.6184 & 33.2601 & <1    \\
                                                & FDM                   & 15.8548  & 17.8439  & 22.6442  & 25.1970  & 27.7465 & 28.9472 & 30.0313 & 32.8549 & <1    \\ \hline
        \multirow{3}[0]{*}{\dataset{Census}}    & KD-CBFS               & 5.6620   & 7.5140   & 9.0070   & 10.3654  & 11.6688 & 12.3068 & 13.3368 & 14.0730 & <1    \\
                                                & V-MDAV                & 5.6620   & 7.5140   & 9.0070   & 10.3654  & 11.6688 & 12.3068 & 13.3368 & 14.0730 & <1    \\ 
                                                & FDM                   & 5.3828   & 7.0645   & 8.7178   & 10.1436  & 11.3940 & 12.6727 & 13.7732 & 14.7735 & <1    \\ \hline
        \multirow{3}[0]{*}{\dataset{EIA}}       & KD-CBFS               & 0.4883   & 0.6727   & 1.7764   & 1.3157   & 2.2141  & 2.9910  & 3.4086  & 3.5474  & <1    \\
                                                & V-MDAV                & 0.4884   & 0.6718   & 1.7693   & 1.3157   & 2.2081  & 2.9917  & 3.4086  & 3.5474  & 1     \\ 
                                                & FDM                   & 0.4808   & 0.7311   & 1.0678   & 1.3533   & 1.7343  & 1.9019  & 2.0491  & 2.1674  & <1    \\ \hline
        \multirow{3}[0]{*}{\dataset{Income}}    & KD-CBFS               & 0.675015 & 0.928399 & 1.19127  & 1.4107   & 1.58581 & 1.80879 & 1.94347 & 2.12738 & 1     \\ 
                                                & V-MDAV                & 0.655816 & 0.928362 & 1.19121  & 1.41074  & 1.58681 & 1.80878 & 1.94346 & 2.12738 & 90    \\
                                                & FDM                   & 0.593726 & 0.838746 & 1.0747   & 1.30892  & 1.5398  & 1.75383 & 1.95588 & 2.15949 & 1     \\ \hline
        \multirow{3}[0]{*}{\dataset{Forest}}    & KD-CBFS               & 0.494946 & 0.703865 & 0.885494 & 1.05023  & 1.20079 & 1.33881 & 1.46986 & 1.59104 & 67    \\
                                                & V-MDAV                &          &          &          &          &         &         &         &         & >3600 \\
                                                & FDM                   & 0.426531 & 0.608566 & 0.782772 & 0.952619 & 1.11867 & 1.28177 & 1.44231 & 1.59784 & 65    \\ \hline
    \end{tabular}%
    \label{tab:results1}%
\end{table}%
\end{document}

And just for comparison, here's an option using the booktabs package

booktabs screenshot

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{multirow}
\usepackage[landscape]{geometry}
\usepackage{siunitx}
\usepackage{booktabs}
\newcommand{\dataset}[1]{#1}

\begin{document}
\begin{table}[htbp]
    \centering
    \caption{Comparison of microaggregation algorithms to protect different datasets for $k=\{3,4,\ldots,10\}$}
    \begin{tabular}{crS[table-format=2.6]S[table-format=2.6]S[table-format=2.6]S[table-format=2.6]S[table-format=2.5]S[table-format=2.5]S[table-format=2.5]S[table-format=2.5]S[table-comparator=true]}
        \toprule
        \multirow{2}[1]{*}{Dataset} & \multirow{2}[1]{*}{Method} & \multicolumn{8}{c}{Information Loss (\%)}                     & \multirow{2}[1]{*}{Elapsed time (sec)} \\
                                                &         & {$k=3$}  & {$k=4$}  & {$k=5$}  & {$k=6$}  & {$k=7$} & {$k=8$} & {$k=9$} & {$k=10$} &       \\
        \midrule
        \multirow{3}[1]{*}{\dataset{Tarragona}} & KD-CBFS & 16.9500  & 19.7700  & 22.8900  & 26.4100  & 28.2600 & 29.3100 & 31.6200 & 33.2600  & <1    \\
                                                & V-MDAV  & 16.9507  & 19.7695  & 22.8867  & 26.4131  & 28.2616 & 29.3119 & 31.6184 & 33.2601  & <1    \\
                                                & FDM     & 15.8548  & 17.8439  & 22.6442  & 25.1970  & 27.7465 & 28.9472 & 30.0313 & 32.8549  & <1    \\ 
        \cmidrule{3-11}
        \multirow{3}[0]{*}{\dataset{Census}}    & KD-CBFS & 5.6620   & 7.5140   & 9.0070   & 10.3654  & 11.6688 & 12.3068 & 13.3368 & 14.0730  & <1    \\
                                                & V-MDAV  & 5.6620   & 7.5140   & 9.0070   & 10.3654  & 11.6688 & 12.3068 & 13.3368 & 14.0730  & <1    \\ 
                                                & FDM     & 5.3828   & 7.0645   & 8.7178   & 10.1436  & 11.3940 & 12.6727 & 13.7732 & 14.7735  & <1    \\ 
        \cmidrule{3-11}
        \multirow{3}[0]{*}{\dataset{EIA}}       & KD-CBFS & 0.4883   & 0.6727   & 1.7764   & 1.3157   & 2.2141  & 2.9910  & 3.4086  & 3.5474   & <1    \\
                                                & V-MDAV  & 0.4884   & 0.6718   & 1.7693   & 1.3157   & 2.2081  & 2.9917  & 3.4086  & 3.5474   & 1     \\ 
                                                & FDM     & 0.4808   & 0.7311   & 1.0678   & 1.3533   & 1.7343  & 1.9019  & 2.0491  & 2.1674   & <1    \\ 
        \cmidrule{3-11}
        \multirow{3}[0]{*}{\dataset{Income}}    & KD-CBFS & 0.675015 & 0.928399 & 1.19127  & 1.4107   & 1.58581 & 1.80879 & 1.94347 & 2.12738  & 1     \\ 
                                                & V-MDAV  & 0.655816 & 0.928362 & 1.19121  & 1.41074  & 1.58681 & 1.80878 & 1.94346 & 2.12738  & 90    \\
                                                & FDM     & 0.593726 & 0.838746 & 1.0747   & 1.30892  & 1.5398  & 1.75383 & 1.95588 & 2.15949  & 1     \\ 
        \cmidrule{3-11}
        \multirow{3}[0]{*}{\dataset{Forest}}    & KD-CBFS & 0.494946 & 0.703865 & 0.885494 & 1.05023  & 1.20079 & 1.33881 & 1.46986 & 1.59104  & 67    \\
                                                & V-MDAV  &          &          &          &          &         &         &         &          & >3600 \\
                                                & FDM     & 0.426531 & 0.608566 & 0.782772 & 0.952619 & 1.11867 & 1.28177 & 1.44231 & 1.59784  & 65    \\ 
        \bottomrule
    \end{tabular}%
    \label{tab:results1}%
\end{table}%
\end{document}
share|improve this answer
    
You can use siunitx in the last column too with: S[table-format=<4.0] (or table-comparator=true). The fourth S column needs table-format=2.6 because of the last row (0.952619). –  Qrrbrbirlbel Sep 21 '13 at 17:01
    
@Qrrbrbirlbel thanks, updated :) –  cmhughes Sep 21 '13 at 17:26

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.