1

could you please fix this table? the columns are night right. I have 5 columns as it shows in the first line of the following code.

    \newcolumntype{C}{>{\centering\arraybackslash}X}
`\lipsum[1]
\begin{table}[!h]
 \caption{Running times in seconds on  symmetric MINLP.}
 \label{Table}
  \begin{tabularx}{\textwidth}{@{} c>{\hsize=0.5\hsize}C
                                 >{\hsize=1.5\hsize}C
                           @{} }
      \toprule
 Name  &  Algorithm & Cycle & Total time (s) & Number of sub-problems \\
\midrule
P1    &   1 & $ (1,2,3,4,5)$ & .. & .. \\
 \midrule
P2 & 2 & $ (1,15,7,5,12) $ & .. & .. \\
 \midrule
   P2 & 3 & $(1,15,7,5,12),(2,9,13,14,8)  $  & ... &...\\
        \midrule
      P3 & 2 & $(1,7,12,16,19,21,6)$   & ... & ...\\
     \midrule
    P3 & 3 & $(1,7,12,16,19,21,6), (2 ,8 ,13, 17, 20, 5, 11)$   & ... & ...\\
     \midrule
   P4 & 2 & $(( 1, 3, 5, 6, 7,22,13,23)$   & ... & ...\\
         \midrule
      P4 & 2 & $( 1, 3, 5, 6, 7,22,13,23), (4,15,16,17,14,21,19,12)$   & ... & ...\\
   \bottomrule
   \end{tabularx}
    \end{table}
   \lipsum[2]`

enter image description here

  • Plese provide a full code. As long as others have to guess how the column type C is defined, the answers will be guesswork. –  Feb 28 '20 at 03:31
  • @Schrödinger'scat see edit plz – user9272398 Feb 28 '20 at 03:45
  • 1
    @Schrödinger'scat The OP has used partially a code provided in an answer by Zarko in this question from the same OP: https://tex.stackexchange.com/questions/530297/what-is-wrong-in-this-table (this later question was flagged duplicate of a older question from the same OP). But in the answer from Zarko, the question was a table with 3 columns, not 5. The OP doesn't have adapted the pattern of the tabularx environment from 3 to 5. – quark67 Feb 28 '20 at 03:48
  • @quark67 Thanks! You could write an answer. (I do not know if one needs nowadays tables which essentially contain lists that get fed into codes.) –  Feb 28 '20 at 08:30

2 Answers2

2

You declare three columns, but use five and running LaTeX will surely show many error messages: never disregard them

The headers take up most of the space, leaving just a small amount for the “Cycle” column. My suggestion is to abbreviate the headers, adding an explanation at the bottom.

\documentclass{article}
\usepackage{tabularx,booktabs}

\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}[!htp]
\caption{Running times in seconds on  symmetric MINLP.}\label{Table}
\begin{tabularx}{\textwidth}{@{}ccCcc@{}}
\toprule
%Name  &  Algorithm & Cycle & Total time (s) & Number of sub-problems \\
N & A & C & TT (s) & NS \\
\midrule
P1 & 1 & $(1,2,3,4,5)$ & .. & .. \\
%\midrule
P2 & 2 & $(1,15,7,5,12)$ & .. & .. \\
%\midrule
P2 & 3 & $(1,15,7,5,12)$, $(2,9,13,14,8)$  & ... &...\\
%\midrule
P3 & 2 & $(1,7,12,16,19,21,6)$   & ... & ...\\
%\midrule
P3 & 3 & $(1,7,12,16,19,21,6)$, $(2,8,13,17,20,5,11)$   & ... & ...\\
%\midrule
P4 & 2 & $(1,3,5,6,7,22,13,23)$   & ... & ...\\
%\midrule
P4 & 2 & $(1,3,5,6,7,22,13,23)$, $(4,15,16,17,14,21,19,12)$   & ... & ...\\
\midrule[\heavyrulewidth]
\multicolumn{5}{@{}l@{}}{N: Name; A: Algorithm; C: Cycle; TT: Total time;}\\
\multicolumn{5}{@{}l@{}}{NS: Number of subproblems}\\
\end{tabularx}
\end{table}

\end{document}

Note that each cycle is typed in its own $...$ symbols, so line breaks are possible when there are more than two of them.

I'd avoid adding rules between each row.

enter image description here

egreg
  • 1,121,712
0

This should meet the requirement -- as pointed out by @quark67 the columns are 5 in number whereas the delimiter & were only 3 in number -- more importantly the OP forgot to enclose with the maths symbol $ outside the braces where a new line was to be enforced in the third column

enter image description here

MWE

\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{makecell, multirow, tabularx}
\usepackage{booktabs, ragged2e} 

\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{%
                             @{}
                             c
                             C
                             C
                             c
                             c
                             @{}} \toprule
 Name  &  Algorithm & Cycle & Total time (s) & Number of  \\ 
                                           &&&&sub-problems\\\midrule
P1    &   1 & $(1,2,3,4,5)$                    & .. & .. \\   \midrule
P2    &   2 & $(1,15,7,5,12)$                 & .. & .. \\     \midrule
P2    &   3 & $(1,15,7,5,12)$, $(2,9,13,14,8)$   & ... &...\\   \midrule
P3    &   2 & $(1,7,12,16,19,21,6)$             & ... & ...\\    \midrule
P3    &   3 & $(1,7,12,16,19,21,6)$, $(2 ,8 ,13, 17, 20, 5, 11)$   & ... & ...\\ 
\midrule
P4    &   2 & $( 1, 3, 5, 6, 7,22,13,23)$      & ... & ...\\        \midrule
P4    &   2 & $( 1, 3, 5, 6, 7,22,13,23)$, $(4,15,16,17,14,21,19,12)$   & ... & ...\\ 
\bottomrule
\end{tabularx}
\end{table}

\end{document}
js bibra
  • 21,280
  • 2
    Your MWE is not compilable since at least \begin{document}\begin{table} are missing. – leandriis Feb 28 '20 at 07:54
  • 1
    Please also explain the purpose of >{\hsize=.5\hsize}c (4th column). Lastly, your choice of \hsize is not ideal since according to the tabularx manual, "the sum of the widths of all the Xcolumns [should stay] unchanged". Could you please comment on that as well? – leandriis Feb 28 '20 at 08:08
  • sorry -- my mistake -- edited – js bibra Feb 29 '20 at 00:26