# Rmarkdown code style in LaTeX

I would like my R code in latex to look like the rmarkdown block of codes: Distinct colours for functions and grey background. I pasted my code between \begin{markdown} and \end{markdown} But this only works for changing latex text to rmarkdown text. I believe I should like in listings or change the background, codecolours manually. Is this possible? Or does someone already programmed rmarkdown code block layout already? Thanks in advance!

• Welcome to TeX.SE! You would do well to show us a minimal working example with what you have tried, so that it'll be easier for us to help you. Dec 12 '19 at 15:25
• Okay. Will add:) Dec 12 '19 at 15:33

The listings package has the option backgroundcolor to change the background of code chunks

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[backgroundcolor = \color{lightgray}]
code block
code block
\end{lstlisting}
\end{document}


Trick to make the area bigger:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[backgroundcolor = \color{lightgray},frame=single,framerule=0pt,framesep=10pt]
code block
code block
\end{lstlisting}
\end{document}

• can we make the shaded area a little bigger code block? Dec 12 '19 at 18:37
• @BlackMild updated
– kaba
Dec 14 '19 at 19:29

To list R code as with knitr in Rmarkdown you can use... knitr:

\documentclass{article}
\begin{document}
<<eval=F>>=
code block
code block
@
\end{document}