1

I currently have a pgfplotstable longtable where the first two of the columns has values given in degrees (e.g. 5.678) but I want to display them in terms of hours:mins:secs. The conversion isn't my problem; my text file will have the right numbers. My question is how best to make the table (or format the txt file so that making the table will be easier) so that I can have the colons in the content of the cells and align based on the first colon. Some ideas I had were:

1) Use dec sep={:} and actually format my txt file with periods (hours.mins.sec) but this fails (I assume because I have multiple decimals in the number as opposed to just one) and also the last decimal needs to be a real decimal and not a placeholder for a colon, so I don't see this working.

2) Format my txt file so the value is split into an hours columns, a mins one, and a secs one, and then use a multicolumn{3}{alignment} and then maybe add a postproc cell content to add the colons, but I am a beginner so I don't think I know how to do that properly. Also, the spacing between columns wouldn't look right.

Does anyone have any other ideas? I could use some major help here! Thanks!

My MWE (for my current table - none of the things I tried would be considered a "working" example):

\documentclass{article}
\usepackage{booktabs} % For \toprule, \midrule and \bottomrule
\usepackage{siunitx} % Formats the units and values
\usepackage{pgfplotstable} % Generates table from .csv
\usepackage{longtable} % To display tables on several pages
\usepackage{array}
\usepackage{bm}
\usepackage{hyperref}

% Setup siunitx:
\sisetup{
  % Rounds numbers
   round-mode          = places,  
  % to 4 places
   round-precision     = 3,
}

\pgfplotsset{compat=1.14} %was giving me backwards compatibility errors

\begin{document}

%%% Code from Dr. Christian for not using headers
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
    \pgfplotstableset{
         empty header/.style={
           every head row/.style={output empty row},
        }
    }
}

\pgfplotstableset{
 begin table=\begin{longtable},
 end table=\end{longtable},
}

\pgfplotstabletypeset[
     empty header,
     col sep=space,
     every head row/.append style={
         before row={%
            \caption{The caption}
            \label{tab:DataTable}
            \\ \toprule
            % the dec sep align options makes two tabular columns, so we need multicolumn for the header
            \multicolumn{2}{c}{\textbf{RA}} & \multicolumn{2}{c}{\textbf{Dec}} & \multicolumn{2}{c}{\textbf{S}} \\
            \multicolumn{2}{c}{\bfseries hh:mm:ss} & \multicolumn{2}{c}{\bfseries deg:min:sec} & \multicolumn{2}{c}{\textbf{mJy}}
            \\ \midrule
            \endfirsthead
            %
            % split this over two lines, so that it doesn't make the table too wide
            \multicolumn{6}{l}{{\bfseries \tablename\ \thetable{} -- continued from}} \\
            \multicolumn{6}{l}{{\bfseries previous page}}
            \\ \toprule
            \multicolumn{2}{c}{\textbf{RA}} & \multicolumn{2}{c}{\textbf{Dec}} & \multicolumn{2}{c}{\textbf{S}}
            \\ \midrule
             \endhead
            %
            \midrule 
            \multicolumn{6}{c}
            {{Continued on next page}} 
            \\ \bottomrule
            \endfoot
            %
            \midrule
            \multicolumn{6}{r}{} 
            \\ \bottomrule
            \endlastfoot
        }
    },
     display columns/0/.style={
         dec sep align,
         fixed, fixed zerofill,
         precision=2
    },
     display columns/1/.style={
         dec sep align,
         fixed, fixed zerofill,
         precision=2
    },
     display columns/2/.style={
         dec sep align,
         fixed, fixed zerofill,
         precision=2
    }
]{data.txt}

\end{document}

Sample file for my current table:

1.00 2.00 3.456
4.00 5.00 4.567
7.00 8.00 5.678

Sample file for suggestion #1 above (all decimals except the last decimal in each value would need to be changed to colons):

01.00.0.00 02.00.0.00 3.456
04.00.0.00 05.00.0.00 4.567
07.00.0.00 08.00.0.00 5.678

Sample file for suggestion #2 above:

01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678

Remember, I only want to change the first two columns.

All thoughts are welcome. Thanks again!

0

I'd opt for suggestion #2, with @{:} as a separator when needed.

I also add some \phantoms to adjust alignment.

\documentclass[a5paper]{article}
\usepackage{array}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{booktabs} 
\usepackage{longtable}
\usepackage{siunitx}

\usepackage{filecontents}
\begin{filecontents}{data.txt}
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
01 00 0.00 02 00 0.00 3.456
04 00 0.00 05 00 0.00 4.567
07 00 0.00 08 00 0.00 5.678
\end{filecontents}

\begin{document}

\pgfplotstableset{
 begin table=\begin{longtable},
 end table=\end{longtable},
}

\pgfplotstableset{
        every head row/.style={output empty row},
        every head row/.append style={before row={%
            \caption{The caption}
            \label{tab:DataTable}\\
                \toprule
                \multicolumn{3}{c}{\textbf{RA}} & \multicolumn{3}{c}{\textbf{Dec}} & \multicolumn{1}{c}{\textbf{S}} \\
            \multicolumn{3}{c}{\bfseries hh:mm:ss} & \multicolumn{3}{c}{\bfseries deg:min:sec} & \multicolumn{1}{c}{\textbf{mJy}}
            \\
                \midrule
                \endfirsthead
                 \multicolumn{7}{c}{\tablename\ \thetable{} -- continued from}\\ 
\multicolumn{7}{c}{previous page}\\[1ex] 
                \toprule
                \multicolumn{3}{c}{\textbf{RA}} & \multicolumn{3}{c}{\textbf{Dec}} & \multicolumn{1}{c}{\textbf{S}} \\
            \multicolumn{3}{c}{\bfseries hh:mm:ss} & \multicolumn{3}{c}{\bfseries deg:min:sec} & \multicolumn{1}{c}{\textbf{mJy}}
            \\
                \midrule
                \endhead
                \midrule
                \multicolumn{7}{r}{Continued on next page}\\
                \endfoot
                \bottomrule
                \endlastfoot
            },
        },      
}

\pgfplotstabletypeset[col sep=space,
columns/0/.style={string type,column type=r,column type/.add={>{\phantom{.}}}{@{:}}},
columns/1/.style={string type,column type=c,column type/.add={}{@{:}}},
columns/2/.style={string type,column type=l},
columns/3/.style={string type,column type=r,column type/.add={>{\phantom{0.}}}{@{:}}},
columns/4/.style={string type,column type=c,column type/.add={}{@{:}}},
columns/5/.style={string type,column type=l},
columns/6/.style={string type,column type={S[table-format=1.2, round-mode=places, 
round-precision=2]}}
]{data.txt}

\end{document}

First page:

enter image description here

Second page:

enter image description here

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.