0

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
  • 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:)
    – Cardinal
    Dec 12 '19 at 15:33
1

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}
2
  • can we make the shaded area a little bigger code block?
    – Black Mild
    Dec 12 '19 at 18:37
  • 1
    @BlackMild updated
    – kaba
    Dec 14 '19 at 19:29
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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.