0

I tried a table that have alighn decimal commas, but this doesn't work. Thank you

Original code:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[czech]{babel} 
\usepackage{tabularx, makecell, boldline}
\usepackage{caption}
\usepackage{cellspace}
\usepackage{etoolbox}
\preto\tabular{\shorthandoff{-}}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{array, cellspace, makecell, multirow, tabularx}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[h!]
\footnotesize
\caption{\small Naměřené amplitudy metodou ($\pi $,$\pi/2$) pro jednotlivé koncentrace}
\centering
\begin{tabular}{V{4}c|c|c|c|c|cV{4}}
    \Xhline{4\arrayrulewidth}
    \rowcolor{gray!25}
    \multicolumn{1}{V{4}cV{2.5}}{$T$ (MJD)} & \multicolumn{1}{V{1.5}cV{2.5}}{\centering $\alpha $} & \multicolumn{1}{V{1.5}cV{2.5}}{\centering $\delta $} & \multicolumn{1}{V{1.5}cV{2.5}}{$B$} & \multicolumn{1}{V{1.5}m{1.2cm}V{2.5}}{\centering $V$} & \multicolumn{1}{V{1.5}m{1.2cm}V{4}}{$B-V$}\\

\Xhline{4\arrayrulewidth}
&&&&&\\[-10pt]
8585,154194&    3h44m03,5s& 24$^\circ$14'37"&   12,193& 12,021& 0,172\\
8585,164329&    3h47m29,1s& 24$^\circ$06'21"&   2,780&  2,870&   -0,090\\
\Xhline{4\arrayrulewidth}

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

I tried:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[czech]{babel} 
\usepackage{tabularx, makecell, boldline}
\usepackage{caption}
\usepackage{cellspace}
\usepackage{etoolbox}
\preto\tabular{\shorthandoff{-}}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{array, cellspace, makecell, multirow, tabularx}
\usepackage[table]{xcolor}
\begin{document}


  \begin{table}[h!]
\footnotesize
\caption{\small Naměřené amplitudy metodou ($\pi $,$\pi/2$) pro jednotlivé koncentrace}
\centering
\begin{tabular}{
@{}
S[table-format=4,6]|
S|
S|
S[table-format=2,3]|
S[table-format=2,3]|
S[table-format=1,3]
@{}
}
    \Xhline{4\arrayrulewidth}
    \rowcolor{gray!25}
    \multicolumn{1}{2.5}{$T$ (MJD)} & \multicolumn{1}{2.5}{\centering $\alpha $} & \multicolumn{1}{2.5}{\centering $\delta $} & \multicolumn{1}{2.5}{$B$} & \multicolumn{1}{1.2cm}{\centering $V$} & \multicolumn{1}{1.2cm}{$B-V$}\\

\Xhline{4\arrayrulewidth}
&&&&&\\[-10pt]
8585,154194&    3h44m03,5s& 24$^\circ$14'37"&   12,193& 12,021& 0,172\\
8585,164329&    3h47m29,1s& 24$^\circ$06'21"&   2,780&  2,870&   -0,090\\


\Xhline{4\arrayrulewidth}

    \end{tabular}
\label{tabt1}
\end{table}
\end{document}
  • Your code is not compilable. Please add a compilable code, otherwise we don't know what you have and what you want. – user156344 Apr 12 at 14:10
  • I editted my question – Lukáš Altman Apr 12 at 14:22
  • Have a look at siunitx with S column (pre-)type. – user156344 Apr 12 at 14:24
  • 1
    How is the V column type defined? And how did you modify the c column type so that it accepts an optional argument? – Mico Apr 12 at 14:30
  • I looked at siunitx and I tried it in the secound code, but it is not compilable. I deleted the V column – Lukáš Altman Apr 12 at 14:57
1

If you want an improvement, here is one.

  • No need of complicated column types
  • Get rid of unnecessary packages
  • Use siunitx to align commas
  • Remove all vertical lines, use \toprule, \midrule, \bottomrule (by booktabs) for table

\documentclass{article}
\usepackage[locale=FR]{siunitx}
\usepackage{booktabs}
\usepackage{geometry}
\begin{document}
\begin{table}
    \centering
    \begin{tabular}{S[table-format=4.6]ccS[table-format=2.3]S[table-format=2.3]S}
    \toprule
        {$T$ (MJD)} & $\alpha$ & $\delta$ & {$B$} & {$V$} & {$B-V$}\\
    \midrule
        8585,154194 & 3h44m03,5s & 24$^\circ$14'37" & 12,193 & 12,021 & 0,172\\
        8585,164329 & 3h47m29,1s & 24$^\circ$06'21" & 2,780 & 2,870 & -0,090\\
    \bottomrule
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}
\end{document}

enter image description here

  • It might make sense to use siunitx also for proper units (duh), viz. \SI{3}{hours} or \SI{3456789045678}{\second}, see also groups.google.com/forum/#!topic/comp.text.tex/7sZRB_dT4RQ – Oleg Lobachev Apr 12 at 17:05
  • @OlegLobachev Yes, I agree. However, that is what the OP has already written, I don't change what the OP writes intentionally. If the OP wants, he can do it himself. – user156344 Apr 12 at 17:07
1

So, I basically combined two existing answers to this and then undid all the hours-minutes and degree-minutes-seconds thing OP had for the sake of scientific consistency, yay.

\documentclass{article}
\usepackage[locale=FR]{siunitx}

%% https://tex.stackexchange.com/a/38957/142180
\ExplSyntaxOn
\NewDocumentCommand \hms { o > { \SplitArgument { 2 } { ; } } m }
  {
    \group_begin:
      \IfNoValueF {#1}
        { \keys_set:nn { siunitx } {#1} }
      \siunitx_hms_output:nnn #2
    \group_end:
  }
\cs_new_protected:Npn \siunitx_hms_output:nnn #1#2#3
  {
    \IfNoValueF {#1}
      {
        \tl_if_blank:nF {#1}
          {
            \SI {#1} { \hour }
            \IfNoValueF {#2} { ~ }
          }
      }
    \IfNoValueF {#2}
      {
        \tl_if_blank:nF {#2}
          {
            \SI {#2} { \minute }
            \IfNoValueF {#3} { ~ }
          }
      }
    \IfNoValueF {#3}
      { \tl_if_blank:nF {#3} { \SI {#3} { \second } } }
  }
\ExplSyntaxOff

%% https://tex.stackexchange.com/a/484535/142180
\usepackage{booktabs}
\usepackage{geometry}
\begin{document}
\begin{table}
    \centering
    \begin{tabular}{S[table-format=4.6]ccS[table-format=2.3]S[table-format=2.3]S}
    \toprule
        {$T$ (MJD)} & $\alpha$ & $\delta$ & {$B$} & {$V$} & {$B-V$}\\
    \midrule
        8585,154194 & \hms{3;44;03,5} & \ang{24}14'37" & 12,193 & 12,021 & 0,172\\
        8585,164329 & \hms{3;47;29,1} & \ang{24}06'21" & 2,780 & 2,870 & -0,090\\
    \bottomrule
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
  \end{table}

  \begin{table}
    \centering
    \begin{tabular}{S[table-format=4.6]S[table-format=5.1]S[table-format=2.5]S[table-format=2.3]S[table-format=2.3]S}
    \toprule
        {$T$ (MJD)} & {$\alpha$, sec} & {$\delta$} & {$B$} & {$V$} & {$B-V$}\\
    \midrule
        8585,154194 & 13443.5 & \ang{24.24361} & 12,193 & 12,021 & 0,172\\
        8585,164329 & 13649.1 & \ang{24.10583} & 2,780 & 2,870 & -0,090\\
    \bottomrule
    \end{tabular}
    \caption{Seconds and decimal degrees}
    \label{tab:my_label2}
\end{table}

\end{document}

as in the previous answer with above macro with seconds and degrees unrolled

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.