Search code examples
rmarkdownbookdownkablernotebook

Kable forces my table above my text in R, how do I fix this?


I am working on the following code with some latex (making a reproducible report document in R notebook, but for some reason my table is put above my text and equation. How do I fix this? enter image description here

title: "Empirical Research in Finance"
subtitle: "**Hypothesis tests and simulation**" 
author: Faes E.
fontsize: 12pt
date: '*January 25, 2021*'
output: 
    pdf_document: default
    html_document:
    df_print: paged
header-includes:
  - \usepackage{amsmath} \usepackage{color}
  - \usepackage{titling}
  - \pretitle{\begin{center}
    \includegraphics[width=4in,height=4in]{AMSLOGO.jpg}\LARGE\\}
  - \posttitle{\end{center}}
\thispagestyle{empty}
# copy the R logo to the current directory
file.copy(file.path(R.home("doc"), "html", "AMSLOGO.jpg"), '.')
\newpage

\newpage

An examination of the first and second moments of the sample skewness is been done in table 1. There can be seen that the mean goes to zero for larger samples. For the variance, the asymptotic variance is being reached. We know that it should render the following values (equation 2) as we know that skewness is asympotitcally distributed with mean 0 and variance 6/n (where n is in this case the sample size).

\begin{equation} 
\tag{2} 
skewness \stackrel{a}{\sim}N(0,\dfrac{6}{n})
\end{equation}

```{r echo=FALSE}
kable(des(mom=S), digits= 3, caption = "Statistics for skewness") %>%
    kable_classic(full_width = F) %>%
     footnote(number = c("n is the sample size","std is the standard deviation"))
```

Solution

  • Like user2554330 answered correctly and worked for me:

    You can use kable(..., format = "latex", position = "h!") to give a very strong suggestion to leave it in place. If LaTeX thinks that's a bad idea, it still won't do it.