1

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. Commented Dec 12, 2019 at 15:25
  • Okay. Will add:)
    – Cardinal
    Commented Dec 12, 2019 at 15:33

2 Answers 2

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
    Commented Dec 12, 2019 at 18:37
  • 1
    @BlackMild updated
    – kaba
    Commented Dec 14, 2019 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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .