2

I would like to combine stargazer (from the same named R package) with \textsubscript to end up with a LaTeX table that looks roughly like this.

enter image description here

My first approach

dat <- data.frame(count = 4000, value = .4)
rownames(dat) <- "NDVI\textsubscript{3g}"

library(stargazer)
stargazer(dat, summary = FALSE)

created this LaTeX tabular code (shortened version)

\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & count & value \\ 
\hline \\[-1.8ex] 
NDVI    extsubscript\{3g\} & $4,000$ & $0.400$ \\ 
\hline \\[-1.8ex] 

i.e., \t was interpreted as TAB. I found here that it is possible to avoid such behavior by adding a second backslash like

dat2 <- data.frame(count = 4000, value = .4)
rownames(dat2) <- "NDVI\\textsubscript{3g}"

stargazer(dat2, summary = FALSE)

but now, the resulting code looks even more weird

\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & count & value \\ 
\hline \\[-1.8ex] 
NDVI\textbackslash textsubscript\{3g\} & $4,000$ & $0.400$ \\ 

Does anybody know how to solve this issue from the R side, i.e., without manually editing the LaTeX code after it has been created via stargazer?

fdetsch
  • 5,239
  • 3
  • 30
  • 58

1 Answers1

0

You need to pass the row names via covariate.labels

stargazer(dat, summary = FALSE, covariate.labels = "NDVI\\textsubscript{3g}")

Which produces the desired output

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: dim., nov. 19, 2017 - 21:49:46
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} ccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
NDVI\textsubscript{3g} & count & value \\ 
\hline \\[-1.8ex] 
1 & $4,000$ & $0.400$ \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
Cedric
  • 2,412
  • 17
  • 31