3

Good day all! I store tables on CSV files and use pgfplotstable package to call the files. This works fine but I have a challenge. I need to bring the units in bracket (i.e (MeV) and (mb/MeV/sr) e.t.c.) to the next line so that I'll have two lines dedicated to the head row and the width of the coulumns does not get too large. I need someone to help me out! Please find below an excerpt of my latex code. Thanks in advance...

\begin{table}
\caption{\label{tab:knockho3}As in table~\ref{tab:knockho1} but for complementary angles of \mbox{$60^\circ - 120^\circ$}.} 
\centering
\resizebox{\columnwidth}{!}{%
\pgfplotstabletypeset[col sep=comma,
    columns/Energy (MeV)/.style={string type},
    columns/Experiment (mb/MeV/sr)/.style={string type},
    columns/Error (mb/MeV/sr)/.style={string type},
    columns/Simulation (mb/MeV/sr)/.style={string type},
    every head row/.style={
        before row=\toprule,
        after row=\midrule},
    every last row/.style={after row=\bottomrule}
    ]{Tables/knockho3.csv}%
}
\end{table}
  • 3
    Hi, welcome to the site! Could you please turn your code snippet into a full minimal example document (so starting from \documentclass) that does not rely on external files (you can include some dummy data inline in the document)? That will make it much easier for others to help you. – Jake Dec 12 '12 at 17:26
4

Answer the Unanswered....

You can either enforce a line break in the header cells via various boxes or just use another row dedicated for the units. A quick example with made-up data and units(hopefully I got the right ones).

\documentclass{article}
\usepackage{pgfplotstable,booktabs,siunitx,array}
\sisetup{per-mode=symbol}
\pgfplotsset{compat=1.13}

\begin{document}
\begin{table}
\caption{Complementary angles of $60^\circ - 120^\circ$.}
\centering
\pgfplotstabletypeset[%col sep=comma,
    header=false,
    columns={[index]0,[index]1,[index]2,[index]3},
    every col no 0/.style={column name=Energy},
    every col no 1/.style={column name=Experiment},
    every col no 2/.style={column name=Error},
    every col no 3/.style={column name=Simulation},
    every head row/.append style={
        before row=\toprule,
        after row/.add={}{%
        \arraybackslash%
        [\si{\mega\electronvolt}]%
        & {[\si{\milli\barn\per\mega\electronvolt\per\steradian}]}%
        & {[\si{\milli\barn\per\mega\electronvolt\per\steradian}]}%
        & {[\si{\milli\barn\per\mega\electronvolt\per\steradian}]}\\ \midrule
        }
    },
    every last row/.style={after row=\bottomrule}
    ]{
1 2 3 4
5 6 7 8
9 10 11 12
}%

\end{table}
\end{document}

enter image description here

  • Your solution gives me a noalign error. Can you update your solution to resolve this error (as this answer is over 4 years old so packages might have changed in the meantime)? – Budo Zindovic May 30 '17 at 12:30
  • It seems that the line \steradian}]}\ \midrule should be \steradian}]}\\ \midrule. – Budo Zindovic May 30 '17 at 12:47
  • 1
    @BudoZindovic It's unfortunately because of this tex.meta.stackexchange.com/questions/7168/… – percusse May 30 '17 at 17:07

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.