如何在tinytex data.table()中获取上标

发布于 2025-01-18 07:39:17 字数 442 浏览 2 评论 0原文

我正在使用data.table()打印表 - 在PDFS中。在这些表中,我想要一些带有上标的文本。我已经尝试了一对夫妻,但是我只找到使用kable()tibble()的解决方案 - 但我真的想使用data。 table()或使用expression() - 我无法在PDF中工作的解决方案。

这是一些简单的示例代码。

library(data.table)

some_table <- data.table(
    element = c('Some text with <1> in superscript at the end',
                'Some more text')
    )

先感谢您!

I am printing tables - in PDFs - by using data.table(). In these tables, I want some texts with superscript. I've tried a couples of things, but I only find solutions which are using kable() or tibble() - but I really want to use data.table() or solutions which are using expression() - which I cannot get working in PDFs.

Here is some simple example code.

library(data.table)

some_table <- data.table(
    element = c('Some text with <1> in superscript at the end',
                'Some more text')
    )

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小耗子 2025-01-25 07:39:17

您可以使用 sup 表示上标,使用 sub 表示下标。也许你想要这样的东西:

library(DT)
some_table <- datatable(
  data.frame(c(1, 2), 
             row.names = c("Some text with A<sup>1</sup>", "Some more text")), rownames = T, escape = FALSE)

some_table

输出:

在此处输入图像描述

data.table 不支持

data.table 包似乎不支持上标表达式。尝试时出现以下错误:

Error in `[.data.table`(x, i, , ) : Internal error: column type 'expression' not supported by data.table subset. All known types are supported so please report as bug.

使用此代码时:

library(data.table)

    my_string <- "'title'^2"
    my_title <- parse(text=my_string)
    
    some_table <- data.table(
        element = c('Some text with', my_title, 'in superscript at the end',
                    'Some more text')
        )
    
    some_table
    ```

It seems currently not available for `data.table`.

You can use sup for superscript and sub for subscript. Maybe you want something like this:

library(DT)
some_table <- datatable(
  data.frame(c(1, 2), 
             row.names = c("Some text with A<sup>1</sup>", "Some more text")), rownames = T, escape = FALSE)

some_table

Output:

enter image description here

Not supported with data.table

It seems like that superscripts expressions are not supported with the data.table package. You get the following error when trying:

Error in `[.data.table`(x, i, , ) : Internal error: column type 'expression' not supported by data.table subset. All known types are supported so please report as bug.

When using this code:

library(data.table)

    my_string <- "'title'^2"
    my_title <- parse(text=my_string)
    
    some_table <- data.table(
        element = c('Some text with', my_title, 'in superscript at the end',
                    'Some more text')
        )
    
    some_table
    ```

It seems currently not available for `data.table`.
§对你不离不弃 2025-01-25 07:39:17

Rmarkdown + LaTeX 的两个选项:

---
title: "Untitled"
output: pdf_document
---

```{r}
library(kableExtra)
levels(iris$Species)[1] <- "setosa\\textsuperscript{*}"
names(iris)[5]          <- "Species$^x$"
kable(iris[1:2, ], format='latex', escape=FALSE)
```

在此处输入图像描述

Two options with Rmarkdown + LaTeX:

---
title: "Untitled"
output: pdf_document
---

```{r}
library(kableExtra)
levels(iris$Species)[1] <- "setosa\\textsuperscript{*}"
names(iris)[5]          <- "Species$^x
quot;
kable(iris[1:2, ], format='latex', escape=FALSE)
```

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文