Graphics, Figures & TablesTable Column Width Adjustment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
erictamlam
Posts: 8
Joined: Sun Apr 29, 2012 7:41 am

Table Column Width Adjustment

Post by erictamlam »

Dear all,

I have a serious problem adjusting the column widths of a table i created. What i tried to achieve is to split the last two combined columns ('transiton probabilites' and 'equilibrium distribution') equally between their subcolumns, i.e., 'p_j' and 'q_j' split the combined column 'transiton probabilites' equally, and so does '\pi_{bj}' and '\pi_{ij}'.
Any help would be deeply appreciated! Thanks in advance :D

Code: Select all

\begin{table}[!h]
    \begin{center}
    \caption{Markov channel parameter settings}
            \begin{tabular}{     
                 c|
                 S[tabnumalign=centre,tabformat=+1.2]|
                 S[tabnumalign=centre,tabformat=+1.2]|
                 S[tabnumalign=centre,tabformat=2]|
                 S[tabnumalign=centre,tabformat=2]
                 }
                \toprule
                \multirow{2}{*}{Channel $j$} & \multicolumn{2}{c}{Transition Probability} & \multicolumn{2}{c}{Equilibrium distribution}\\
                \cmidrule(l){2-3}\cmidrule(l){4-5}
                 & $p_j$ & $q_j$ & $\pi_{bj}$ & $\pi_{ij}$\\
                \midrule
                 1 & 0.1     & 0.4     & 0.2      & 0.8     \\
                 2 & 0.2     & 0.6     & 0.25     & 0.75    \\
                 3 & 0.3     & 0.7     & 0.3      & 0.7     \\
                 4 & 0.3     & 0.5     & 0.375    & 0.625   \\
                 5 & 0.35    & 0.65    & 0.35     & 0.65    \\
                 6 & 0.4     & 0.6     & 0.4      & 0.6     \\
                 7 & 0.6     & 0.6     & 0.5      & 0.5     \\
                 8 & 0.6     & 0.4     & 0.6      & 0.4     \\
                \bottomrule
            \end{tabular}
            \label{tab:markovchapara}
    \end{center}
\end{table}
Attachments
table.jpg
table.jpg (25.97 KiB) Viewed 5447 times
Last edited by localghost on Sun Apr 29, 2012 2:43 pm, edited 2 times in total.

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table Column Width Adjustment

Post by localghost »

A belated answer, but perhaps still useful.

The trick is to drop the \multicolumn commands and slightly modify the table head instead. Furthermore it needs the correct specification for the number format in the S type columns. The below solution needs siunitx version 2.x (or higher).

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{booktabs,multirow}
\usepackage{siunitx}

\captionsetup{
  font=small,
  labelfont=bf,
  tableposition=top
}


\begin{document}
  \begin{table}[!ht]
    \caption{Markov channel parameter settings}
    \centering
    \label{tab:markovchapara}
    \begin{tabular}{    
      c
      S[table-format=1.2]
      @{~}
      S[table-format=1.2]
      S[table-format=1.3]
      @{~}
      S[table-format=1.3]
    }\toprule
      \multirow{2}{*}[-0.5ex]{Channel $j$} & {Transition} & {Probability} & {Equilibrium} & {distribution} \\ \cmidrule(r){2-3}\cmidrule(l){4-5}
        & {$p_j$} & {$q_j$} & {$\pi_{bj}$} & {$\pi_{ij}$} \\ \midrule
      1 & 0.1     & 0.4     & 0.2      & 0.8     \\
      2 & 0.2     & 0.6     & 0.25     & 0.75    \\
      3 & 0.3     & 0.7     & 0.3      & 0.7     \\
      4 & 0.3     & 0.5     & 0.375    & 0.625   \\
      5 & 0.35    & 0.65    & 0.35     & 0.65    \\
      6 & 0.4     & 0.6     & 0.4      & 0.6     \\
      7 & 0.6     & 0.6     & 0.5      & 0.5     \\
      8 & 0.6     & 0.4     & 0.6      & 0.4     \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
It is suggestive to drop vertical lines in tables completely in order to improve their readability.


Thorsten
Attachments
The resulting output.
The resulting output.
table-markov.png (16.99 KiB) Viewed 5317 times
Post Reply