[Tex/LaTex] How to change a table column type in the middle of table

columnstables

I have a table with a column that I need to change its type in the middle of the table.

For example, I have a part of the table in which the column will hold a typeset number with some decimal points and some alignment. After some rows, I need the same column to be a simple number (no decimal alignment) and with a different alignment.

For example, something in the lines of

\documentclass{article}

\usepackage{siunitx}

\begin{document}
\begin{tabular}{lS[table-format=3.2]}
  \multicolumn{2}{l}{\textbf{Part 1}} \\
  Number & 100 \\
  Number & 2.00 \\
  % Somehow change the row format
  \newrowformat{rS[table-format=1]}
  \multicolumn{2}{l}{\textbf{Part 2}} \\
  Right & 1 \\
  Rigth &10 \\
\end{tabular}
\end{document}

I know that I can use a \multicolumn 1-column span hack to change the type of each cell, but I wanted a more flexible solution that allows me to change the type from that point onwards.

How can I achieve that?

Best Answer

I suggest you simply set up two separate tabular environments, with one row of each tabular (likely the header row) containing information about the (ex-ante fixed) width of each column.

In the following example, vertical lines are used in each tabular purely to demonstrate that they line up across the two environments.

enter image description here

\documentclass{article}
\usepackage{siunitx}
\newlength{\mylen}
\setlength{\mylen}{1in} % desired width of first column
\newcommand\slug{\hphantom{123456}} % set desired width of "slug" used in column 2

\begin{document}
\begin{center}
\begin{tabular}{|l|S[table-format=3.2]|}
  \multicolumn{1}{|p{\mylen}|}{\textbf{Part 1}} & {\slug} \\
  Number & 100  \\
  Number & 2.00 \\
\end{tabular}\\[-0.25ex] % snug up the two tabulars
\begin{tabular}{|r|S[table-format=1]|}
  \multicolumn{1}{|p{\mylen}|}{\textbf{Part 2}} & {\slug} \\
  Right &  1 \\
  Right & 10 \\
\end{tabular}
\end{center}
\end{document}
Related Question