vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
196 stars 16 forks source link

Using "notes" adds empty label and entry, thereby overriding \\label in title when using LaTeX #290

Closed cportner closed 3 months ago

cportner commented 3 months ago

Since modelsummary no longer seems to play nice with kable_styling and kableExtra, I am trying to move to tinytable. However, one problem I have not been able to fix is that my labels are overridden when I use notes.

For example, if I run

ancova %>% 
  modelsummary(
    title = "ANCOVA Estimation of Treatment Effect on Total Births in 2014 Wave \\label{tab:ancova}",
    coef_rename = rename_vars,
    gof_map = list(
      list("raw" = "nobs", "clean" = "Number of observations", "fmt" = my_big_f),
      list("raw" = "# FE", "clean" = "Number of subdistricts", "fmt" = my_big_f)
    ),
    # notes = "\\footnotesize{Note: Standard errors clustered at branch level and shown in parentheses. Subdistrict fixed effects included in all estimations}",
    output = "tinytable"
  ) %>% 
  save_tt(here("tables", "ancova.tex"), overwrite = TRUE)

I get

\begin{table}
\centering
\begin{talltblr}[         %% tabularray outer open
caption={ANCOVA Estimation of Treatment Effect on Total Births in 2014 Wave \label{tab:ancova}},
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
column{3}={halign=c,},
column{4}={halign=c,},
column{5}={halign=c,},
column{6}={halign=c,},
hline{6}={1,2,3,4,5,6}{solid, 0.05em, black},
}                     %% tabularray inner close
\toprule
& Full sample & 14-22 & 23-27 & 28-32 & 33-40 \\ \midrule %% TinyTableHeader
Treated                       & 0.063   & -0.045  & 0.032   & 0.057   & 0.021   \\
& (0.017) & (0.081) & (0.062) & (0.041) & (0.040) \\
Children ever born at baseline & 0.899   & 0.714   & 0.883   & 0.968   & 1.014   \\
& (0.013) & (0.061) & (0.031) & (0.021) & (0.014) \\
Number of observations         & 2,487   & 411     & 606     & 635     & 835     \\
Number of subdistricts         & 20      & 20      & 20      & 20      & 20      \\
\bottomrule
\end{talltblr}
\end{table}

But once I add the notes, I get

\begin{table}
\centering
\begin{talltblr}[         %% tabularray outer open
caption={ANCOVA Estimation of Treatment Effect on Total Births in 2014 Wave \label{tab:ancova}},
entry=none,label=none,
note{}={\footnotesize{Note: Standard errors clustered at branch level and shown in parentheses. Subdistrict fixed effects included in all estimations}},
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
column{3}={halign=c,},
column{4}={halign=c,},
column{5}={halign=c,},
column{6}={halign=c,},
hline{6}={1,2,3,4,5,6}{solid, 0.05em, black},
}                     %% tabularray inner close
\toprule
& Full sample & 14-22 & 23-27 & 28-32 & 33-40 \\ \midrule %% TinyTableHeader
Treated                       & 0.063   & -0.045  & 0.032   & 0.057   & 0.021   \\
& (0.017) & (0.081) & (0.062) & (0.041) & (0.040) \\
Children ever born at baseline & 0.899   & 0.714   & 0.883   & 0.968   & 1.014   \\
& (0.013) & (0.061) & (0.031) & (0.021) & (0.014) \\
Number of observations         & 2,487   & 411     & 606     & 635     & 835     \\
Number of subdistricts         & 20      & 20      & 20      & 20      & 20      \\
\bottomrule
\end{talltblr}
\end{table}

which results in Pandoc no longer being able to identify the label and telling me that the reference is undefined. Any suggestions for how to fix this?

cportner commented 3 months ago

It looks like https://github.com/vincentarelbundock/tinytable/blob/39e5f3a6b8ff898ce26cc8f9cd4ccd9f3b9e6c67/R/tt_tabularray.R#L80 is the "offending" line since that adds the "entry=none,label=none," part when adding a note, although it is unclear to me whether this might be needed by another format.

vincentarelbundock commented 3 months ago

Thanks for digging into the code. I really appreciate the effort!

Your diagnosis is probably correct. I'm at a conference now but will look into this when I get back to the office.

vincentarelbundock commented 3 months ago

Should be fixed in version 0.3.0.15 from Github. Thanks again for the report.