11

I wish to use in line R code as part of a header in a r markdown file. However when i knit the file the fonts used on the header are different. How can I ensure the fonts are the same. A simple example is below.

`r 1+1`  Header 
-------------------------
3
  • If it does not work, the only reason that I can think of is that your knitr version is too old. You may need to update.packages(). See FAQ 1. Commented Feb 23, 2013 at 5:48
  • Strange, it works just fine for me. Perhaps I'm also using an old version of knitr. checks Commented Feb 23, 2013 at 8:29
  • Apparently I was using 0.8. Most recent version on CRAN is 1.1. Commented Feb 23, 2013 at 8:30

2 Answers 2

9

You can wrap content in backticks to denote r code inline, as follows:

## Title `r 1+1` Header
Sign up to request clarification or add additional context in comments.

1 Comment

I needed to put a $ before the first backtick and after the last backtick.
2

Without a reproducible example it is hard to be precise, but one thing you might want to consider is to use the results="asis" chunk option in your R code so that the results are not wrapped in a code markup block. I am not sure how this works with inline commands, but you could use a regular R block and have it create the entire header from the R code, something like:

```r results="asis"
cat('# ', 1+1, " Header")
```

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.