0

I am the author of the question: Problem with a table with special header: bolded numbers are badly aligned with the rest of the numbers

Following Zarko's advise, I have revised my code according to his suggestion to get my bolded number aligned in the right way. However, a new problem is popping up. I am making another post because I can't share the updated version of my code in my previous post.

I am trying to make a table with special header.

I tried the following code:

\documentclass[11pt,a4paper]{article}
\usepackage[hyperref]{NAACL2019}
\usepackage[skip=1ex,font=small]{caption}
\usepackage{times}
\usepackage{url}
\usepackage{latexsym}
\usepackage{algorithm} 
\usepackage{algpseudocode} 
\usepackage{sectsty}
\usepackage{amssymb}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{amsmath,epsfig,times}
\usepackage{tabularx} 
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage{subcaption}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx}  % <---
\usepackage{etoolbox} % <--- 
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries} % <===

\usepackage{hyperref} % load this package last

\begin{table}[ht] \sisetup{detect-weight, mode=text, table-format=1.4} \centering \begin{tabular}{l SS S[table-format=-1.2] S[table-format=1.2] } \toprule & \multicolumn{2}{c}{M1}
& \multicolumn{2}{c}{M2} \ \cmidrule(lr){2-3} \cmidrule(l){4-5} & {1-2} & {7-8} & {1-2} & {7-8} \ \midrule A & \B{0.0021} & \B{0.0033} & -2.37 & 0.00 \ B & \B{0.0052} & \B{0.0042} & -1.23 & 0.67 \ C & 0.0960 & \B{0.0054} & -0.62 & 1.10 \ D & \B{0.0082} & \B{0.0057} & -0.21 & 1.08 \ E & 0.0107 & 0.0097 & 0.74 & 1.41 \ F & \B{0.0080} & 0.0088 & 5.05 & 5.05 \ G & 0.0140 & 0.0148 & -2.37 & 0.00 \ H & 0.0128 & 0.0176 & -1.23 & 0.67 \ I & 0.0157 & 0.0164 & -0.62 & 1.10 \ J & 0.0145 & 0.0155 & -0.21 & 1.08 \ K & 0.0205 & 0.0209 & 0.74 & 1.41 \ L & 0.0236 & 0.0225 & 5.05 & 5.05 \ \bottomrule \end{tabular}%} \smallskip \caption{My Caption} \label{tab:table1} \end{table}

But it gives the following result:

enter image description here

The problem here is that there is [rm]bfb right before each bolded number, which I want to remove.

How can I resolve this issue?

PS: For my LaTeX document, I am using this specific template for a particular academic conference: https://www.overleaf.com/latex/templates/instructions-for-naacl-hlt-2019-proceedings/xyyfwfkswhth

This conference template is 2-columned, that is, the texts are displayed on each page in 2 columns.

Thank you,

chico0913
  • 138
  • Before you even take a look at the pdf, fix all the error messages you get. Also, clean up your preamble to make youre you don't load packaes multiple times. Lastly, make sure, hyperrefis the last package in your preamble (There are only a few exceptions, that should be loaded after it.) – leandriis Oct 24 '20 at 13:21
  • Having fixed the errors related to the preamble/packages, we still end up with an error message such as "Extra alignment tab has been changed to \cr.". This is caused by an extra & throughout the whole table. To fix this, replace all occurences of two subsequent & by a single&. – leandriis Oct 24 '20 at 13:25
  • Ok, I will fix them right now – chico0913 Oct 24 '20 at 13:27
  • @leandriss there is not extra & in the table, because I am using \multicolumn. The extra & are meant to be there. – chico0913 Oct 24 '20 at 13:30
  • The error message is caused because you use more columns than you declared. With \begin{tabular}{l SS S[table-format=-1.2]S[table-format=1.2]} you declare a total of 5 columns, while a line such as G & 0.0140 & 0.0148 & & -2.37 & 0.00 \\ uses a total of 6 column. Thus replace & & with a single &. – leandriis Oct 24 '20 at 13:32
  • BTW, table produced provided MWE, is narrow enough that it can be placed in the single column. – Zarko Oct 24 '20 at 14:12
  • After clean up your document preamble (remove twice loaded package, push hyperref on the end of preamble) and remove curly braces around numeral marked by \B (this was not done in my answer https://tex.stackexchange.com/questions/568080/problem-with-a-table-with-special-header-bolded-numbers-are-badly-aligned-with/568085#568085 !) I'm not able to reproduce your problem. You should be careful using my solution/suggestion ... – Zarko Oct 24 '20 at 14:19

1 Answers1

0

You wrote,

a table with special header that includes bolded number

I can see no bolded numbers in the "special header". What I do see is a number of specious and unnecessary & symbols that are causing various issues. Remove them, and the code compiles fine.

I can also see no reason for employing the \scalebox directive -- unless, that is, you want to deliberately sabotage the look of the table. Oh, please don't load latexsym if you also load amssymb, and please don't load packages more than once.

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage[skip=1ex,font=small]{caption}
\usepackage{times}
\usepackage{xurl} % 'xurl' is more capable than 'url'
%%%\usepackage{latexsym}
\usepackage{algorithm} 
\usepackage{algpseudocode} 
\usepackage{sectsty}
\usepackage{amssymb}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{amsmath,%%%epsfig,times
  }
\usepackage{tabularx} 
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{siunitx}  % <---
\usepackage{etoolbox} % <--- 
\newrobustcmd\B{%
\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries} % <===

\usepackage{hyperref} % load this package last

\begin{document} \begin{table}[ht] \sisetup{detect-weight, mode=text, table-format=1.4} \centering %\scalebox{0.65}{ \begin{tabular}{l SS S[table-format=-1.2] S[table-format=1.2] } \toprule & \multicolumn{2}{c}{M1}
& \multicolumn{2}{c}{M2} \ \cmidrule(lr){2-3} \cmidrule(l){4-5} & {1-2} & {7-8} & {1-2} & {7-8} \ \midrule A & \B{0.0021} & \B{0.0033} & -2.37 & 0.00 \ B & \B{0.0052} & \B{0.0042} & -1.23 & 0.67 \ C & 0.0960 & \B{0.0054} & -0.62 & 1.10 \ D & \B{0.0082} & \B{0.0057} & -0.21 & 1.08 \ E & 0.0107 & 0.0097 & 0.74 & 1.41 \ F & \B{0.0080} & 0.0088 & 5.05 & 5.05 \ G & 0.0140 & 0.0148 & -2.37 & 0.00 \ H & 0.0128 & 0.0176 & -1.23 & 0.67 \ I & 0.0157 & 0.0164 & -0.62 & 1.10 \ J & 0.0145 & 0.0155 & -0.21 & 1.08 \ K & 0.0205 & 0.0209 & 0.74 & 1.41 \ L & 0.0236 & 0.0225 & 5.05 & 5.05 \ \bottomrule \end{tabular}%} %%\smallskip \caption{My Caption} \label{tab:table1} \end{table}

\end{document}

Mico
  • 506,678
  • hello, thank you for your reply. after done all the changes that you recommend, I still get the [rm]bfb right before each bolded number in the table, which I want to remove; I don't know why this is happening...could you help me with that? – chico0913 Oct 24 '20 at 13:42
  • Also, I need to use the scalebox since my LaTeX template is two-columned. If I use it without scalebox, then the table goes outside of the border for a single column – chico0913 Oct 24 '20 at 13:43
  • Also, after your recommended changes, I get the undefined sequence error on my table. – chico0913 Oct 24 '20 at 13:47
  • 1
    @chico0913: Which control sequence is undefined specifically? Regarding the use of \scalebox: There are better ways to make sure your table fits into the available space. \scalebox just results in inconsistent font sizes. Alternatively, you could use something like \setlength{\tabcolsep}{0pt} \small \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l SS S[table-format=-1.2] S[table-format=1.2] } For more techniques, see also: My table doesn't fit; what are my options? – leandriis Oct 24 '20 at 14:00
  • Hello, I am getting undefined sequence error for the rows A,B,C, and D. – chico0913 Oct 24 '20 at 14:04
  • @chico0913 - The code I posted does not generate errors. If you are getting errors in your document, it must be the case that your code differs materially, in some ways, from mine; unfortunately, my psychic divination skills are worthless, and hence I'm in no position to tell what these material differences might be. If you're using a two-column format, that's something which is (a) quite important and (b) worthy of mentioning up front in your query. Finally, I've never before heard of an "undefined sequence" error message. Please elaborate. – Mico Oct 24 '20 at 14:26
  • @Mico as David has pointed out (https://tex.stackexchange.com/questions/568151/removing-rmbfb-that-appears-before-each-bolded-number-in-the-table?noredirect=1#comment1432331_568151), this was due to the version of my texlive was 2019. After switching to texlive 2020, I was able to resove the issue. – chico0913 Oct 24 '20 at 14:34
  • Is the NAACL2019.sty LaTeX style file available online? It doesn't appear to be distributed with TeXLive. Incidentally, why do you keep loading latexsym and epsfig, and what's the purpose of loading times twice? – Mico Oct 24 '20 at 14:35
  • yes. I included the link for the overleaf NAACL template in my question here. Also, note that the table itself is not my entire LaTeX document. My entire document is 8 pages long, which I need to use the packages latexsym and epsfig for certain parts. Anyway, the issue is resolved now after switching to texlive 2020, thanks to David. – chico0913 Oct 24 '20 at 14:39
  • @chico0913 - The latexsym package was superseded by the amssymb package in 1994; the epsfig package's functionality is subsumed by that of the graphicx package. – Mico Oct 24 '20 at 14:42