I am using ggplot/R for report generation and want more fine-grained control over text formatting.
我正在使用ggplot / R生成报告,并希望对文本格式进行更细粒度的控制。
It's trivial to write some text, apply global formatting parameters, and output to a grid-graphics compatible object - just use textGrob.
编写一些文本,应用全局格式化参数以及输出到网格图形兼容对象是很简单的 - 只需使用textGrob。
t <- textGrob(
label = "SOME TEXT"
,gp=gpar(fontsize=20, col="grey")
)
print(arrangeGrob(t))
Problem is that those formatting options only apply to the entire text string. What I'm looking for is something that would offer basic inline formatting options (font size, bold, italic, etc) - ideally something lightweight like Markdown/CSS/HTML. If I have to learn LaTeX, so be it, but that seems like overkill for what I'm trying to accomplish here.
问题是那些格式化选项仅适用于整个文本字符串。我正在寻找的东西将提供基本的内联格式化选项(字体大小,粗体,斜体等) - 理想情况下像Markdown / CSS / HTML一样轻量级。如果我必须学习LaTeX,那就这样吧,但这似乎有点过分,因为我在这里想要完成的事情。
Any thoughts?
有什么想法吗?
1 个解决方案
#1
1
You can use a "text cursor" alongside grid
's functions for interrogating grobs
. Say you had the phrase: "I want this text bold!!!!!!!, and you want the exclamation points in red:
您可以使用“文本光标”和网格功能来查询凹凸。假设您有这样的短语:“我希望这个文字大胆!!!!!!!,并且您希望感叹号为红色:
grid.text("I want ",
name="notboldtext",
hjust=0)
text.cursor<-convertWidth(grobWidth("notboldtext") # Adds textGrob width & to location
+ unit(.5, "npc"), "npc")
grid.text("this text bold",
x=text.cursor,
gp=gpar(fontface="bold"),
name="boldedtext",
hjust=0)
text.cursor<- text.cursor + convertWidth(grobWidth("boldedtext"), "npc")
grid.text("!!!!!!!",
gp=gpar(col="red"),
x=text.cursor,
name="maptextnat",
hjust=0)
#1
1
You can use a "text cursor" alongside grid
's functions for interrogating grobs
. Say you had the phrase: "I want this text bold!!!!!!!, and you want the exclamation points in red:
您可以使用“文本光标”和网格功能来查询凹凸。假设您有这样的短语:“我希望这个文字大胆!!!!!!!,并且您希望感叹号为红色:
grid.text("I want ",
name="notboldtext",
hjust=0)
text.cursor<-convertWidth(grobWidth("notboldtext") # Adds textGrob width & to location
+ unit(.5, "npc"), "npc")
grid.text("this text bold",
x=text.cursor,
gp=gpar(fontface="bold"),
name="boldedtext",
hjust=0)
text.cursor<- text.cursor + convertWidth(grobWidth("boldedtext"), "npc")
grid.text("!!!!!!!",
gp=gpar(col="red"),
x=text.cursor,
name="maptextnat",
hjust=0)