简体   繁体   English

R Markdown kable 表使用 $ 登录列名称 html output

[英]R Markdown kable table using $ sign in column name for html output

I'm wanting to include the units in my column description for a kable table in R Markdown with html output. Basically for each cost I want 'Cost Min ($k)', 'Cost Mode ($k)' and 'Cost Max ($k)' as 3 of my column names.我想在 R Markdown 和 html output 中的 kable 表的列描述中包含这些单位。基本上对于每个成本,我想要“Cost Min ($k)”、“Cost Mode ($k)”和“Cost Max” ($k)' 作为我的列名中的 3 个。

It works fine for my first table but then for my second it is outputting it with strange formatting and not reading each column name correctly.它适用于我的第一个表,但对于我的第二个表,它以奇怪的格式输出它并且没有正确读取每个列名。

输出

My code is as follows:我的代码如下:


Summary<- matrix(c(0.90,0.99,1000,3000,5000,0.90,0.99,1000,3000,5000,0.30,0.60,500,750,1000), ncol=5,byrow=TRUE)

colnames(Summary)<-c("Probability Lower","Probability Upper" , "Cost Min ($k)" , "Cost Mode ($k)" , "Cost Max ($k)")
rownames(Summary)<-c("Start", "Current", "Target")
SummaryTable<-as.table(Summary)

knitr::kable(SummaryTable, format = "html") %>%
  kableExtra::kable_styling(SummaryTable,bootstrap_options = "bordered")

Any help would be much appreciate as I would like all my tables to look like the one that is working.任何帮助将不胜感激,因为我希望我的所有表格看起来都像正在工作的表格。

Laura劳拉

Try using two backslashes before the dollar sign, like this: \\$ :尝试在美元符号前使用两个反斜杠,如下所示: \\$

colnames(Summary)<-as.character(c("Probability Lower","Probability Upper" , "Cost Min (\\$k)" , "Cost Mode (\\$k)" , "Cost Max (\\$k)"))
rownames(Summary)<-c("Start", "Current", "Target")

在此处输入图像描述

R markdown 多列布局 - 如何使用 CSS 和 HTML 固定列宽<div> ?</div><div id="text_translate"><p> 亲爱的乐于助人的社区,</p><p> 几个小时以来,我一直在尝试找到一种方法,将两个元素并排放置在 R markdown<strong>中,同时控制布局中列的宽度</strong>(对于 html 输出)。</p><p> 我<a href="https://community.rstudio.com/t/rmarkdown-place-figure-and-table-side-by-side-in-html-document/146181" rel="nofollow noreferrer">找到了这个线程</a>并非常快地实现了它。 但是,我不知道如何强制列宽为 10% 和 90%。</p><p> 我想在一些文本旁边放一个标志。 根据上述线程,我首先创建一行,并在其中嵌套两列。 我知道.column {flex;50%}可能会影响我能做什么,但我只是想不出我应该使用的语法。 同一列中的两个文本块位于另一列中的表格旁边(理想情况下为宽度的 70% 和 30%)。</p><p> 注意:我宁愿不必为样式创建 .css 文件,因为我需要将脚本应用于许多单独的结果文件,所以我需要一个简单的嵌入式解决方案。 我不想要需要向同事复制/更新/解释的 .css 文件。</p><p> 我尝试了所有我能找到的列宽语法,唯一有影响的是,<a href="https://getbootstrap.com/docs/4.0/layout/grid/" rel="nofollow noreferrer">正如此处所建议的那样</a>,正在编写<div class = "col-4">但将数字更改为 -1 或 -8 并没有改变结果和专栏太大了,另一个太小了。 现在我再试一次,它不再起作用了,我非常困惑。</p><p> 另外,有趣的是 padding style="padding-right:50px;" 语法有效,但宽度语法无效,例如width = "block-size: 4000px;" .</p><p> 非常感谢您的帮助!</p><p> 这是我的代码(抱歉,您必须用其他东西替换徽标):</p><pre> --- title: Report of analyses output: html_document: theme: yeti --- <style type="text/css">.main-container {max-width: 80%;}.row {display: flex;}.column {flex;50%} </style> <div class = "row"> <div class = "column">:[](C./NKUA-logo-red.png){#id,class width=10% height=10%} </div> <div class = "column"> *I want this affiliation to be wider. like 90% of the total width with the logo to the left,* Department of Clinical Therapeutics: <br> *Report author, Jane Doe, PharmD: PhD* </div> </div> <div class = "row"> <div class = "column" style="padding-right;50px."> *I want both these paragraphs 1.&2, to be wider. like 70% of the total width.* ### 1: Pathology interpretation **Technical summary**. Lorem ipsum dolor sit amet ### 2, Case details and history Lorem ipsum dolor sit amet, consectetur adipiscing elit. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua, Ut enim ad minim veniam. quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat, </div> <div class = "column"> *I want this table to be more narrow to the right. like 30% of the total width.* ### 3: Information ```{r echo = FALSE} library(kableExtra) kbl(iris[1,10,])</pre><pre></pre></div> - R markdown multi column layout - how to fix the width of a column using CSS & HTML <div>?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 kable 垂直对齐列名并使用 rmarkdown 渲染成 html - Vertically align column name using kable and rendering with rmarkdown into html Plot and table in one figure in R markdown for HTML output - Plot and table in one figure in R markdown for HTML output 带有 html/docx 输出的 R Markdown 文档,使用 LaTeX 包 bbm? - R Markdown document with html/docx output, using LaTeX package bbm? R knitr - 小文本的 kable 表格 html 格式 - R knitr - kable table html formatting for small text "R Markdown HTML 输出到 Sharepoint 的渲染问题" - Render Issues for R Markdown HTML Output to Sharepoint R Markdown HTML 输出与 R Studio 输出不匹配 - R Markdown HTML output doesn't match the R Studio output R markdown:将html表下载到excel文件 - R markdown: download a html table to an excel file R/markdown:在表格内渲染 html 标签 - R/markdown: rendering html tags inside table R markdown 多列布局 - 如何使用 CSS 和 HTML 固定列宽<div> ?</div><div id="text_translate"><p> 亲爱的乐于助人的社区,</p><p> 几个小时以来,我一直在尝试找到一种方法,将两个元素并排放置在 R markdown<strong>中,同时控制布局中列的宽度</strong>(对于 html 输出)。</p><p> 我<a href="https://community.rstudio.com/t/rmarkdown-place-figure-and-table-side-by-side-in-html-document/146181" rel="nofollow noreferrer">找到了这个线程</a>并非常快地实现了它。 但是,我不知道如何强制列宽为 10% 和 90%。</p><p> 我想在一些文本旁边放一个标志。 根据上述线程,我首先创建一行,并在其中嵌套两列。 我知道.column {flex;50%}可能会影响我能做什么,但我只是想不出我应该使用的语法。 同一列中的两个文本块位于另一列中的表格旁边(理想情况下为宽度的 70% 和 30%)。</p><p> 注意:我宁愿不必为样式创建 .css 文件,因为我需要将脚本应用于许多单独的结果文件,所以我需要一个简单的嵌入式解决方案。 我不想要需要向同事复制/更新/解释的 .css 文件。</p><p> 我尝试了所有我能找到的列宽语法,唯一有影响的是,<a href="https://getbootstrap.com/docs/4.0/layout/grid/" rel="nofollow noreferrer">正如此处所建议的那样</a>,正在编写<div class = "col-4">但将数字更改为 -1 或 -8 并没有改变结果和专栏太大了,另一个太小了。 现在我再试一次,它不再起作用了,我非常困惑。</p><p> 另外,有趣的是 padding style="padding-right:50px;" 语法有效,但宽度语法无效,例如width = "block-size: 4000px;" .</p><p> 非常感谢您的帮助!</p><p> 这是我的代码(抱歉,您必须用其他东西替换徽标):</p><pre> --- title: Report of analyses output: html_document: theme: yeti --- <style type="text/css">.main-container {max-width: 80%;}.row {display: flex;}.column {flex;50%} </style> <div class = "row"> <div class = "column">:[](C./NKUA-logo-red.png){#id,class width=10% height=10%} </div> <div class = "column"> *I want this affiliation to be wider. like 90% of the total width with the logo to the left,* Department of Clinical Therapeutics: <br> *Report author, Jane Doe, PharmD: PhD* </div> </div> <div class = "row"> <div class = "column" style="padding-right;50px."> *I want both these paragraphs 1.&2, to be wider. like 70% of the total width.* ### 1: Pathology interpretation **Technical summary**. Lorem ipsum dolor sit amet ### 2, Case details and history Lorem ipsum dolor sit amet, consectetur adipiscing elit. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua, Ut enim ad minim veniam. quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat, </div> <div class = "column"> *I want this table to be more narrow to the right. like 30% of the total width.* ### 3: Information ```{r echo = FALSE} library(kableExtra) kbl(iris[1,10,])</pre><pre></pre></div> - R markdown multi column layout - how to fix the width of a column using CSS & HTML <div>? 使用 R Markdown 和 HTML output 将数学表达式显示为非斜体 - display math expression as non-italic using R Markdown and HTML output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM