2

I have a table with multi-rows and columns. I need to specify the column width of some of the columns because the table is too wide for the page. But I can't find a way to do so and vertically center the text.

I currently have

    \begin{table}[t!]
    \centering
    \caption{Comparison of the median simulated settling time, normalized path length, and final angular velocity of the minimize-torque controller, maximize-force controller, and greedy controller with $q=0$, $q=1$, and $q=3$, using a gentle position controller ($\alpha = 0.99$) and one that is approximately $3\times$ more aggressive ($\alpha = 0.97$). For each metric, the lowest (i.e., best) value is denoted with an $\ast$, and the values of the other controllers are shown as multiples of the respective lowest value. 
    }
    \begin{tabular}{\textwidth} { |c|c|c|c|c|c|c| }\hline
        \multicolumn{2}{|c|}{} & Min-Torque & Max-Force & Greedy, $q = 0$ & Greedy, $q = 1$ & Greedy, $q = 3$  \\
        \hline
        \multirow{2}{6.3em}{Settling Time} &  $\alpha = 0.97$  & 1.46 & 1.04 & 1.04 & * & 1.41  \\
         &  $\alpha = 0.99$  & 1.45 & 1.05 & 1.05 & * & 1.41 \\
        \hline
        \multirow{2}{6.3em}{Normalized Path Length} &  $\alpha = 0.97$  & 1.09 & * & * & 1.02 & 1.07  \\
         &  $\alpha = 0.99$  & 1.08 & * & * & 1.01 & 1.07 \\
        \hline
        \multirow{2}{6.3em}{Final Angular Velocity} &  $\alpha = 0.97$  & * & 9.14 & 11.58 & 9.33 & 9.29  \\
         &  $\alpha = 0.99$  & * & 9.10 & 10.06 & 9.08 & 9.79 \\
        \hline
    \end{tabular}    
    \label{table:boxplot}
    \end{table}

which produces:

enter image description here

I've also tried:

    \begin{table}[t!]
    \centering
    \caption{Comparison of the median simulated settling time, normalized path length, and final angular velocity of the minimize-torque controller, maximize-force controller, and greedy controller with $q=0$, $q=1$, and $q=3$, using a gentle position controller ($\alpha = 0.99$) and one that is approximately $3\times$ more aggressive ($\alpha = 0.97$). For each metric, the lowest (i.e., best) value is denoted with an $\ast$, and the values of the other controllers are shown as multiples of the respective lowest value. 
    }
    \begin{tabularx}{\textwidth} { 
      | >{\centering\arraybackslash}X 
      | >{\centering\arraybackslash}X
      | >{\centering\arraybackslash}X
      | >{\centering\arraybackslash}X
      | >{\centering\arraybackslash}X
      | >{\centering\arraybackslash}X
      | >{\centering\arraybackslash}X | }\hline

        \multicolumn{2}{|c|}{} & Min-Torque & Max-Force & Greedy, $q = 0$ & Greedy, $q = 1$ & Greedy, $q = 3$  \\
        \hline
        \multirow{2}{6.3em}{Settling Time} &  $\alpha = 0.97$  & 1.46 & 1.04 & 1.04 & * & 1.41  \\
         &  $\alpha = 0.99$  & 1.45 & 1.05 & 1.05 & * & 1.41 \\
        \hline
        \multirow{2}{6.3em}{Normalized Path Length} &  $\alpha = 0.97$  & 1.09 & * & * & 1.02 & 1.07  \\
         &  $\alpha = 0.99$  & 1.08 & * & * & 1.01 & 1.07 \\
        \hline
        \multirow{2}{6.3em}{Final Angular Velocity} &  $\alpha = 0.97$  & * & 9.14 & 11.58 & 9.33 & 9.29  \\
         &  $\alpha = 0.99$  & * & 9.10 & 10.06 & 9.08 & 9.79 \\
        \hline
    \end{tabularx}    
    \label{table:boxplot}
    \end{table}

which produces:

enter image description here

Any Help?

Ok, Sorry,

I'm still having some problems. The following code:

\begin{table}[t]
\caption{Comparison of the median simulated settling time, normalized path length, and final angular velocity of the minimize-torque controller, maximize-force controller, and greedy controller with $q=0$, $q=1$, and $q=3$, using a gentle position controller ($\alpha = 0.99$) and one that is approximately three times more aggressive ($\alpha = 0.97$). For each metric, the lowest (i.e., best) value is denoted with an asterisk, and the values of the other controllers are shown as multiples of the respective lowest value. }
\label{table:boxplot}

\begin{tblr}{hlines, vlines,
             colspec = {X[2,l] c *{5}{X[c, m]}},
             row{3}  = {mode=math},
             cell{1}{1,2}  = {r=3}{},
             cell{1}{3}    = {c=5}{},
             cell{2}{3,4}  = {r=2}{},
             cell{2}{5}    = {c=3}{},
             cell{even}{1} = {r=2}{}
             }
    &   $\alpha$ 
            &   Controller type     
                    &       &       &       &       \\
    &       &   Min  Torque
                    &   Max  Force
                            &   Greedy   
                                    &       &       \\
    &       &       &       & q = 0 & q = 1 & q = 3 \\
Settling Time 
    & 0.97  & 1.46  & 1.04  & 1.04  & *     & 1.41  \\
    & 0.99  & 1.45  & 1.05  & 1.05  & *     & 1.41  \\
Normalized Path Length
    & 0.97  & 1.09  & *     & *     & 1.02  & 1.07  \\
    & 0.99  & 1.08  & *     & *     & 1.01  & 1.07  \\
Final Angular Velocity 
    & 0.97  & *     & 9.14  & 11.58 & 9.33  & 9.29  \\
    & 0.99  & *     & 9.10  & 10.06 & 9.08  & 9.79  \\
\end{tblr}
\end{table}

Produces The following:

Resulting Table

Overleaf gives me the following error on the \end{tblr} line: "package xcolor Error: Undefined color `mode'." I'd also like to get rid of the black line. Any help would be very much appreciated.

Also, I obviously need some help getting the code to show up as code here rather than just hard to read text. I click the {} symbol that says "code sample" in the text editor and than paste the code where it says, but it still comes out as just text. Any help there?

2

3 Answers 3

1

Something like this? Note that I've (a) provided more structure to the header material and (b) given the table a more open "look" by getting rid of all vertical rules and employing fewer, but well-spaced, horizontal rules.

enter image description here

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs,amsmath}
\newcolumntype{C}{>{\Centering}X}

\newcommand\mytabL[1]{\smash[b]{\begin{tabular}[t]{@{} l @{}} #1 \end{tabular}}}
\newcommand\mytabC[1]{\smash[b]{\begin{tabular}[t]{@{} c @{}} #1 \end{tabular}}}

\begin{document}

\begin{table}[t!]

\caption{Comparison of the median simulated settling time, normalized path length, and final angular velocity of the minimize-torque controller, maximize-force controller, and greedy controller with $q=0$, $q=1$, and $q=3$, using a gentle position controller ($\alpha = 0.99$) and one that is approximately three times more aggressive ($\alpha = 0.97$). For each metric, the lowest (i.e., best) value is denoted with an asterisk, and the values of the other controllers are shown as multiples of the respective lowest value. }
\label{table:boxplot}

\medskip
\begin{tabularx}{\textwidth}{@{} l c CCCCC @{}}
\toprule
& $\alpha$ & \multicolumn{5}{c@{}}{Controller type}\\
\cmidrule(l){3-7}
 & & \mytabC{Min-\\Torque} & \mytabC{Max-\\Force} & \multicolumn{3}{c@{}}{Greedy}\\
\cmidrule(l){5-7}
& & & &  $q = 0$ &  $q = 1$ &  $q = 3$  \\
\midrule
    \mytabL{Median simul.\\settling time} &   0.97  & 1.46 & 1.04 & 1.04 & * & 1.41  \\
     &   0.99  & 1.45 & 1.05 & 1.05 & * & 1.41 \\
    \addlinespace
    \mytabL{Normalized\\path length} &   0.97  & 1.09 & * & * & 1.02 & 1.07  \\
     &   0.99  & 1.08 & * & * & 1.01 & 1.07 \\
    \addlinespace
    \mytabL{Final angular\\ velocity} &   0.97  & * & 9.14 & 11.58 & 9.33 & 9.29  \\
     &   0.99  & * & 9.10 & 10.06 & 9.08 & 9.79 \\
\bottomrule
\end{tabularx}
 
\end{table}

\end{document}
1
  • That is a lot closer, Thanks. I want the lines though. I added them back in but it is doing a weird dash thing. Can you help. I'll put this my edited version of your code below. I also want alpha and settling time centered horizontally. Sep 13, 2023 at 21:44
1

Since you prefer to have all lines in the table, the tabularray package might come in handy. Using it and defining multi-row cells where needed, the MWE can be refined to be:

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs}


\begin{document}
    \begin{table}[ht]
\caption{Comparison of the median simulated settling time, normalized path length, and final angular velocity of the minimize-torque controller, maximize-force controller, and greedy controller with $q=0$, $q=1$, and $q=3$, using a gentle position controller ($\alpha = 0.99$) and one that is approximately three times more aggressive ($\alpha = 0.97$). For each metric, the lowest (i.e., best) value is denoted with an asterisk, and the values of the other controllers are shown as multiples of the respective lowest value. }
\label{table:boxplot}

\begin{tblr}{hlines, vlines,
             colspec = {X[2,l] c *{5}{X[c, m]}},
             row{3}  = {mode=math},
             cell{1}{1,2}  = {r=3}{},
             cell{1}{3}    = {c=5}{},
             cell{2}{3,4}  = {r=2}{},
             cell{2}{5}    = {c=3}{},
             cell{even}{1} = {r=2}{}
             }
    &   $\alpha$ 
            &   Controller type     
                    &       &       &       &       \\
    &       &   Min  Torque
                    &   Max  Force
                            &   Greedy   
                                    &       &       \\
    &       &       &       & q = 0 & q = 1 & q = 3 \\
Median simul. settling time
    & 0.97  & 1.46  & 1.04  & 1.04  & *     & 1.41  \\
    & 0.99  & 1.45  & 1.05  & 1.05  & *     & 1.41  \\
Normalized espace
    & 0.97  & 1.09  & *     & *     & 1.02  & 1.07  \\
    & 0.99  & 1.08  & *     & *     & 1.01  & 1.07  \\
Final angular velocity
    & 0.97  & *     & 9.14  & 11.58 & 9.33  & 9.29  \\
    & 0.99  & *     & 9.10  & 10.06 & 9.08  & 9.79  \\
\end{tblr}
    \end{table}
\end{document}
1

If you prefer to have all the rules in the table, here is a way to create it with {NiceTabular} of nicematrix. However, like many people, I recommend a version with booktabs in the spirit of booktabs.

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table}[ht]
\caption{Comparison of the median simulated settling time, normalized path length, and final angular velocity of the minimize-torque controller, maximize-force controller, and greedy controller with $q=0$, $q=1$, and $q=3$, using a gentle position controller ($\alpha = 0.99$) and one that is approximately three times more aggressive ($\alpha = 0.97$). For each metric, the lowest (i.e., best) value is denoted with an asterisk, and the values of the other controllers are shown as multiples of the respective lowest value. }
\label{table:boxplot}

\begin{NiceTabular}{X[2,l] c *{5}{X[c, m]}}[hvlines,cell-space-limits=2pt]
\Block{3-1}{} & \Block{3-1}{$\alpha$} 
            &   \Block{1-*}{Controller type} \\
    &       &   \Block{2-1}{Min  Torque}
                    &   \Block{2-1}{Max  Force}
                            &   \Block{1-*}{Greedy} \\
    &       &       &       & $q = 0$ & $q = 1$ & $q = 3$ \\
\Block{2-1}{Median simul. settling time}
    & 0.97  & 1.46  & 1.04  & 1.04  & *     & 1.41  \\
    & 0.99  & 1.45  & 1.05  & 1.05  & *     & 1.41  \\
\Block{2-1}{Normalized espace}
    & 0.97  & 1.09  & *     & *     & 1.02  & 1.07  \\
    & 0.99  & 1.08  & *     & *     & 1.01  & 1.07  \\
\Block{2-1}{Final angular velocity}
    & 0.97  & *     & 9.14  & 11.58 & 9.33  & 9.29  \\
    & 0.99  & *     & 9.10  & 10.06 & 9.08  & 9.79  \\
\end{NiceTabular}

\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

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