Graphics, Figures & Tableschange the order of columns of a table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

change the order of columns of a table

Post by NELLLY »

Hi I Typsetted a table in latex. After doing so I need to unterchange the order of certain columns to avoid rewritting it.

Code: Select all

\documentclass[a4paper]{article}
\usepackage{xstring}
\usepackage{array,booktabs, multirow}
 \setlength{\tabcolsep}{0.3cm}
\begin{table}[bth]
\caption{.....} \centering
\begin{tabular}{cccccccccc}\toprule[1.2pt]
~~&Run&$S^*_B$&$h^*_B$&$n^*_{B}$&$ETCU^*$&$\bigtriangleup C_{B|static}$&$N_c$&$p^*_{S}$&$S^*_{S}$\\\midrule
~~&1&	128&	0.55&	1	&1.17&	24.03&	11	&0.017&	108\\
\end{tabular}
\end{table}
I need to swap the colums such that the column labels and their contents of the new table are in the following specific order:

Code: Select all

H    Run    $h^*_B$    $n^*_{B}$   $ETCU^*$  $S^*_B$  $S^*_{S}$  $p^*_{S}$ $N_c$  $\bigtriangleup C_{B|static}$
I tried a solution using \swapcol through using the array package but it doesn't work for me since I have several columns to interchange.
Is there a solution?
Thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: change the order of columns of a table

Post by Johannes_B »

Post number 100, congratulations :-)


I think this is nothing to tackle on the LaTeX side, though it might be possible. Do you have a good text editor, like vim (emacs seems to be good as well). Maybe notepad++ can do the job as well ... a rectangular area you can cut and past, not only parts of lines. A powerful editor might be a bit harder to learn (just like LaTeX), but can save you a huge amount of time in the end.


Another possible way would be to export the table to a simple text document, open it with excel, swap columns, write and insert in your tex-file.
I would prefer the first method, much simpler ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Re: change the order of columns of a table

Post by NELLLY »

Hi Johannes_B. I searched while a time on the net to search a solution to made for the latex table. I will use an excel sheet to permute the columns and then copy them into the latex document. This will be much easier and time saving also.
Many thanks.
Post Reply