problem rendering rmarkdown pdf

Can you at least format the issue correctly

FAQ: How to Format R Markdown Source

If Rmd works well, it means this is something in your environment somehow. When you click render button, it will call rmarkdown::render() in a background session. When you call in R Console, it will use the current environment. Maybe there is a difference in both, or in the way you are calling in console that is different that was is called when clicking the knit button.

Anyway, hard to help more without being able to reproduce. I can only give general hints