There are probably two problems that are not connected to each other.
First, output in notebook vs html/pdf. It's difficult for me to understand what exactly is the issue. From your example they look identical, but with obvious differences between having one inside of notebook, while second is rendered in HTML with HTML stylings, so that makes sense. knitr::kable() creates a template (you can see what it looks like if you just run knitr::kable(mtcars), for example). How it's rendered is up to environment it is printed at.
Your second issue is not connected, I think, so it would be helpful if you can provide a reprex to see what might be an issue there.