I searched for this, but wasn't able to find it. In a knitr document, I want to put $\alpha_1$ as the caption to a plot like so:
<<fig.cap='$\alpha_1$'>>=
plot(1:5,1:5)
@
Trying to knit this comes back with the error
! Text line contains an invalid character.
l.172 ...axwidth]{figure/plotSigma1} \caption[$^^G
lpha_1$]{$^^Glpha_1$\label...
Is there a way?
You can add a Greek letter to your document by using the command that corresponds with the Greek letter you wish to enter. Commands for Greek letters in LaTeX are the same as the name of the letter, e.g., $\alpha$ , $\beta$ , $\gamma$ .
Put it in math mode: $\gamma$.
Nevermind - you simply need to escape the \ for alpha
<<fig.cap='$\\alpha_1$'>>=
plot(1:5,1:5)
@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With