Maximilian
Maximilian

Reputation: 4229

Include sterling symbol in xtable

I'm failing to figure out how to include valid £ sign into knitr document. It keeps appearing as L alphabet.

Sample data:

require(xtable)

df <- data.frame(x=seq(1,10,1),y=rnorm(10))
colnames(df) <- c("ID",paste("VALUE IN","\u00A3",sep=" "))

Xtab <- xtable(df, digits=0, caption="\\textbf{MINIMAL/IDEAL}")
align(Xtab) <- c( "l|","c","p{0.9in}") 

print(Xtab, size = "small")

So far so good, R prints the £ sign correctly into the R console. However it fails to show correctly in the generated pdf document.

I also included encoding but problem remains. I read about double escaping but the £ sign if double escaped appears as \\u00A3 in document.

knit("file.Rmd", encoding = "UTF-8") 

EDIT: If I just include paste("VALUE IN","€",sep=" ") it works but not with if I replace the with £ as this shows up as L alphabet. Why is this?

Upvotes: 2

Views: 351

Answers (1)

Maximilian
Maximilian

Reputation: 4229

So it works with the following for me:

paste("VALUE IN",sep=" ",`Encoding<-`("£", "UTF8"))

Hence direct embedded encoding. Interestingly (for me) if you run the above in R console it shows as L alphabet but in the rendered document it shows correctly as sterling £.

Upvotes: 2

Related Questions