3

For my new research paper, I am having tough time in formatting a comparison table using LaTeX. I used the recent help given to me in preparing a table using multicolumn but specifically I find some extra space between the output of the code (enclosed).. There is extra space between C2 and C3 columns and I have no idea how to fix this problem. Also, I like to merge the three rows with System 1 into one row with three cases A, B and C, and similarly for the three rows with System 2. I understand that multirow is the command to be used, but I request you to kindly help me with it. In future, I shall format tables with the help I hope to get for the enclosed code.

Thank you for the great help!!

Best wishes, Sundar

\documentclass[11pt]{article}

\usepackage{float}
\usepackage{amssymb}


\usepackage{graphicx}
\usepackage{subfig}

\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}%

\begin{document} 

 \begin{table}
\caption{Comparison Table}
\centering
\begin{tabular}{lcccccc}
  \toprule
  Name of the System & Case &  \multicolumn{3}{c}{Lyapunov Exponents} & Maximum Value & Pascal  Dimension \\
  \cmidrule{3-5}% added
                     &               &      $C1$ & $C2$ & $C3$ &  &  \\                                                  
  \midrule
  System (1) & A & a1 & a2 & a3 & a1 & P1 \\[1mm] \hline 
   System (1) & B & b1 & b2 & b3 & b1 & P2 \\[1mm] \hline 
    System (1) & C & c1 & c2 & c3 & c1 & P3 \\[1mm] \hline 
     System (2) & A & d1 & d2 & d3 & d1 & Q1 \\[1mm] \hline 
      System (2) & B & e1 & e2 & e3 & e1 & Q2 \\[1mm] \hline 
       System (2) & C & f1 & f2 & f3 & f1 & Q3 \\[1mm] \hline 
  \bottomrule
\end{tabular}
\end{table}
\end{document}

LaTeX Output

2

2 Answers 2

4

The following solution uses the w column type (provided by the array package) instead of the basic c column type for the three columns below "Lyapunov exponents". It also introduces line breaks in the header cells of the final two columns to help assure that the tabular material will fit inside the width of the text block.

enter image description here


Addendum: In case you're wondering how I came up with

\setlength{\mylen}{(\widthof{Lyapunov exponents}-4\tabcolsep)/3}

here goes.

  • The length macro \mylen stores the usable width of the three columns below the header "Lyapunov exponents"; the objective is to find the minimum value of \mylen such that the three columns are evenly spaced. For simplicity, let's call the width of the string "Lyapunov exponents" z; z may be determined as \widthof{Lyapunov exponents}, where \widthof is a macro provided by the calc package.

  • By convention, if the usable width of a tabular column is x, then the overall width of that column is x+2\tabcolsep, as LaTeX inserts whitespace on both sides of a column, in the amount of \tabcolsep. Thus, the overall width of the three combined underlying columns is 3\mylen+6\tabcolsep, where \mylen is the length we need to determine.

  • The second piece of information is that the overall width of the 3 combined columns is z+2\tabcolsep; the 2\tabcolsep addendum results from the whitespace padding that LaTeX inserts on either side of the combined header.

  • If we equate the entities 3\mylen+6\tabcolsep and z+2\tabcolsep, we obtain a linear equation with one known variable (z), one constant (\tabcolsep), and one unknown variable (\mylen). What remains to be done is to solve for \mylen.


\documentclass[11pt]{article}

\usepackage{amssymb,amsmath}
\usepackage{graphicx,subfig,float}
\usepackage{array} % for 'w' column type
\usepackage{booktabs,caption}

% new:
\captionsetup{skip=0.333\baselineskip} % default: 1\baselinskip
\usepackage{calc} % simplify calculations 
\newlength\mylen  % scratch length parameter 
\newcommand\mytab[1]{%
   \smash[b]{\begin{tabular}[t]{@{}c@{}}#1\end{tabular}}}

\begin{document} 

\begin{table}

\setlength{\mylen}{% % calculate _usable_ width of middle-3 columns
  (\widthof{Lyapunov exponents}-4\tabcolsep)/3}
\caption{Comparison Table}
\centering
\begin{tabular}{@{} l c *{3}{w{c}{\mylen}} c c @{}}
  \toprule
  Name of system & Case & 
  \multicolumn{3}{c}{Lyapunov exponents} & 
  \mytab{Maximum\\ value} & 
  \mytab{Pascal\\ dimension} \\
  \cmidrule(lr){3-5}
  & & C1 & C2 & C3 \\                                                  
  \midrule
  System 1   & A & a1 & a2 & a3 & a1 & P1 \\ 
             & B & b1 & b2 & b3 & b1 & P2 \\ 
             & C & c1 & c2 & c3 & c1 & P3 \\ 
  \addlinespace % <-- new
  System 2   & A & d1 & d2 & d3 & d1 & Q1 \\ 
             & B & e1 & e2 & e3 & e1 & Q2 \\ 
             & C & f1 & f2 & f3 & f1 & Q3 \\ 
  \bottomrule
\end{tabular}
\end{table}

\end{document}
2
  • 1
    I tested your answer.. It compiles beautifully and I get the output as desired.. You are a genius! Thanks a lot for great help!
    – Dr. Sundar
    Nov 26, 2023 at 9:58
  • @Dr.Sundar - Let me return the compliment by noting that you posted an excellent minimum working example (MWE) for me to work with.
    – Mico
    Nov 26, 2023 at 10:08
3

An alternative:

  • for table I would use table type, for which I can prescribed table width, for example tabularx or tabularray
  • use of tblr of tabularray package enables to determine ratio between widths of column, so for simplicity of code I would use it:
\documentclass[11pt]{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{caption}%

\begin{document}

 \begin{table}[ht]
\caption{Comparison Table}
\centering
\begin{tblr}{colspec = {@{} X[l] *{4}{X[0.5,c]}  *{2}{X[c]} @{}},
             cell{1}{1,2,6,7} = {r=2}{},
             row{2}  = {mode=math}
             }
    \toprule
Name of the System 
    &   Case 
        &  \SetCell[c=3]{c}   Lyapunov Exponents  
            &   &   &   Maximum Value 
                        & Pascal  Dimension         \\
    \midrule
           &   & C1 & C2 & C3 &    &   \\
    \midrule
System (1) & A & a1 & a2 & a3 & a1 & P1 \\
System (1) & B & b1 & b2 & b3 & b1 & P2 \\
System (1) & C & c1 & c2 & c3 & c1 & P3 \\
    \addlinespace
System (2) & A & d1 & d2 & d3 & d1 & Q1 \\
System (2) & B & e1 & e2 & e3 & e1 & Q2 \\
System (2) & C & f1 & f2 & f3 & f1 & Q3 \\
  \bottomrule
\end{tblr}
    \end{table}
\end{document}

enter image description here

2
  • Should it be *{6}{X[c]} or *{2}{X[c]}?
    – Mico
    Nov 27, 2023 at 1:06
  • 1
    @Mico, ups, the second one: *{2}{X[c]}. Corrected now!
    – Zarko
    Nov 27, 2023 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .