0

Why is the header overlaps in the following table: enter image description here and how can I improve it?

\begin{table}[H]
        \centering
        \sisetup{table-format=1.3e-2, table-alignment=center, tight-spacing}
        \setlength{\tabcolsep}{3pt}
        \small
        \centering

        \sisetup{detect-weight,mode=text}
        \renewrobustcmd{\bfseries}{\fontseries{b}\selectfont}
        \renewrobustcmd{\boldmath}{}
        % abbreviation
        \newrobustcmd{\B}{\bfseries}
        % shorten the intercolumn spaces
        \addtolength{\tabcolsep}{-4.1pt}

        \begin{tabularx}{\linewidth}{X cSS[table-format=1.5] SS[table-format=1.5]}
            \toprule
            \thead {Algorithm\\ Name}  & {\thead{ABC Dataset \\ Name} }& {\thead{Bxxx ABS Txx\\ aaaa $80\%$ }} & {\thead{Mxxx YYYYYYY Tcxx\\ Tzzz $80\%$} }
            & {\thead{Bxxx sdsdf Tfds\\Tdfs $90\%$}} \\ [0.5ex]
            \midrule
            ABCD & XXXXX YYY & 0.222 & 0.228 & \B 0.230 \\
            ABCD & DEFG       & 0.222 & \B 0.282 & 0.222 \\
            ABCD & ABCD       & 0.992 & 0.992 & \B 0.998 \\
            ABCD & XXXXX Y    & 0.992 & 0.992 & \B 0.992 \\ 
            DEF  & XXXXX Hand & 0.220 & \B 0.222 & 0.222 \\
            DEF  & DEFG       & 0.223 & 0.232 & \B 0.22 \\
            DEF  & ABCD       & 0.999 & \B 2.000 & 0.999 \\
            DEF  & XXXXX YY   & 0.998 & \B 0.999 & 0.998 \\ [2ex]
            \bottomrule
        \end{tabularx}
        \caption{Cfdfsd (In \textbf{Bold} the gsfdsd per line)}
    \label{table:4}
    \end{table}
Avi
  • 713
  • 2
    You can improve the quality of your screen shots first... and I asked you this morning to provide compilable documents, not just fragments –  Jan 01 '18 at 13:30
  • 2
    is it related to your question https://tex.stackexchange.com/questions/408334/reducing-table-width/? if it is, why you not consider the answer there which you accepted? – Zarko Jan 01 '18 at 13:35
  • @Zarko: That's what I thought too... –  Jan 01 '18 at 13:36
  • please fix your example so that it is a complete document so that people can see the issue, currently it is just a fragment of code using many non standard commands that you do not say how they are defined. (none of \bottomrule, tabularx , \newrobustcmd, \sisetup are defined by default – David Carlisle Jan 01 '18 at 13:44
  • Dear All. It is not connected to my previous question. Even if I add the {tabularx}{0.6\linewidth} still I have a slight overlapping in the header. – Avi Jan 01 '18 at 13:44
  • @Avi: The 0.6\linewidth I suggested in a comment to your other question was a guess only, I did not check. If that value does not fit, you've to increase it accordingly. –  Jan 01 '18 at 13:48
  • Yes but I all I need is to improve the header in this time. How can I do it? – Avi Jan 01 '18 at 13:50
  • 1
    there is no reason at all to use tabularx here (that is designed to control line breaking within table cells, but you do not want linebreaks in a data table like this) just use a standard tabular but unless you provide a proper example we have no information about the width of the column, so can not suggest how much the table needs to shrink. – David Carlisle Jan 01 '18 at 13:50
  • but in my answer is not used tabularx ... you also have issues with number of columns. – Zarko Jan 01 '18 at 13:51
  • Can you please show your answer to this specific example. Since I need a left alignment of the second column. In addition, there are bold numbers inside the table. Thank you very much. – Avi Jan 01 '18 at 13:57

2 Answers2

4

i suspect that you like to have your table like this:

enter image description here

it is based on my answer to your previous question

\documentclass{article}
\usepackage{booktabs, makecell}
\usepackage{siunitx}

\usepackage{etoolbox}%  <---
\newcommand{\B}{\fontseries{b}\selectfont} %  <---
\robustify\B%  <---

\begin{document}
    \begin{table}
    \centering
\sisetup{detect-weight} %  <---
    \centering
\begin{tabular}{l c *{3}{S[table-format=1.3]}} %  <---
    \toprule
\thead{Algorithm\\ Name}
     & \thead{ABC Dataset \\ Name} 
                        & {\thead{Bxxx ABS Txx \\ 
                                 aaaa \SI{80}{\%} }} 
                                & {\thead{Mxxx YYYYYYY\\ 
                                          Tcxx Tzzz \SI{80}{\%} }}
                                            & {\thead{Bxxx sdsdf Tfds \\
                                                      Tdfs \SI{90}{\%}}}
                                                        \\                                               
     \midrule
    ABCD & XXXXX YYY    & 0.222 &    0.228 & \B 0.230 \\
    ABCD & DEFG         & 0.222 & \B 0.282 &    0.222 \\
    ABCD & ABCD         & 0.992 &    0.992 & \B 0.998 \\
    ABCD & XXXXX Y      & 0.992 &    0.992 & \B 0.992 \\
    DEF  & XXXXX Hand   & 0.220 & \B 0.222 &    0.222 \\
    DEF  & DEFG         & 0.223 &    0.232 & \B 0.22  \\
    DEF  & ABCD         & 0.999 & \B 2.000 &    0.999 \\
    DEF  & XXXXX YY     & 0.998 & \B 0.999 &    0.998 \\
    \bottomrule
    \end{tabular}
    \caption{11 my caption}
\label{table:3}
    \end{table}
\end{document}

Note:

  • always provide complete small document, which we can copy and compile in our computers. for example, your code snippet doesn't provide important information from preamble or you have them on the wrong place in document
  • if you have follow-up question (as your question is), please provide link to previous one
  • if you accept answer from your previous question, please use it in your similar table design

edit: sorry, in the first version of answer in rash i didn't consider your table body, now i correct this now. with it you have some new issues:

  • table is significantly wider as in your previous question
  • for column headers are used theads from makecell package (similar as Bernard do in his answer) since you use siunitx package you should use it in seting percentages values.
Zarko
  • 296,517
2

Your S columns have inconsistent table-format: by default you have a format in scientific notation, some in the table have 5 decimal digits, but you actually have 3. Also you have one unused S column. Also, it would be better to set the 2nd column as a X column.

Here's the code I propose:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{etoolbox}
\usepackage{tabularx, booktabs, makecell} %

\begin{document}

\begin{table}[!htb]
    \centering
    \sisetup{table-format=1.3, table-number-alignment=center, tight-spacing,}% table-column-width =2.5cm 
    \setlength{\tabcolsep}{3pt}
    \small
    \centering

    \sisetup{detect-weight,mode=text}
    \renewrobustcmd{\bfseries}{\fontseries{b}\selectfont}
    \renewrobustcmd{\boldmath}{}
    % abbreviation
    \newrobustcmd{\B}{\bfseries}
    % shorten the intercolumn spaces
    \setlength{\tabcolsep}{4pt}

    \begin{tabularx}{\linewidth}{l>{\centering}XSSS}
        \toprule
        \thead {Algorithm\\ Name} & {\thead{ABC Dataset \\ Name} }& {\thead{Bxxx ABS Txx \\ aaaa $80\%$ }} & {\thead{Mxxx YYYYYYY\\ Tcxx Tzzz $80\%$} }
        & {\thead{Bxxx sdsdf Tfds \\Tdfs $90\%$}} \\ [0.5ex]
        \midrule
        ABCD & XXXXX YYY & 0.222 & 0.228 & \B 0.230 \\
        ABCD & DEFG & 0.222 & \B 0.282 & 0.222 \\
        ABCD & ABCD & 0.992 & 0.992 & \B 0.998 \\
        ABCD & XXXXX Y & 0.992 & 0.992 & \B 0.992 \\
        DEF & XXXXX Hand & 0.220 & \B 0.222 & 0.222 \\
        DEF & DEFG & 0.223 & 0.232 & \B 0.22 \\
        DEF & ABCD & 0.999 & \B 2.000 & 0.999 \\
        DEF & XXXXX YY & 0.998 & \B 0.999 & 0.998 \\ [2ex]
        \bottomrule
    \end{tabularx}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350