user15437862
user15437862

Reputation: 23

how to read superscripts from excel with out changing format into r-markdown pdf?

I want to display superscript in my pdf using r-markdown. How can i display superscripts as superscripts without changing. i'm trying to display this in latex chunk

enter image description here


df<- read_excel("../df.xlsx",sheet = 'sheet1' )

`r df$text`

Upvotes: 0

Views: 403

Answers (3)

jimbrig
jimbrig

Reputation: 127

Another solution since you are using RMarkdown is to intermix HTML and utilize the <sub> superscript tag. Just an idea if you can avoid latex.

For latex, though, I would just manually adjust the value in your latex:

i.e. change seller(1) to seller^{(1)}

LaTeX handles superscripted superscripts and all of that stuff in a natural way. It even does the right thing when something has both a subscript and a superscript.

With @Wimpel 's answer, you can automate the process by pre-determining which values in the excel cells had superscripts at least. Still, I don't see how an XML-based Excel read would know how to convert to latex through markdown automatically.

Upvotes: 0

Anu
Anu

Reputation: 116

from what i look from your code this may help

add this piece of code in excel file where ever superscript is required

$\textsuperscript{1}$

Upvotes: 0

Wimpel
Wimpel

Reputation: 27732

Consider the following excel file superscript.xlsx

enter image description here

library(tidyxl)
library(tidyverse)

# Read in cells from excel
cells <- tidyxl::xlsx_cells("./data/superscript.xlsx")
# Get formatting
final <- cells %>%
  # Keep relevant columns
  dplyr::select(sheet, address, character, format = character_formatted) %>%
  # Spread cells with mixed formatting over over multiple rows
  tidyr::unnest(cols = c(format), names_sep = "_")

Now you can see what p[art of the text is formatted (with superscript), use this info in your markdown..

enter image description here

As you canb see above, from the content of cell A1, the 2-part of test2 is formatted with superscript.

Upvotes: 2

Related Questions