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!
2 Answers
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? Commented Dec 12, 2019 at 18:37
-
1
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}