---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output:
bookdown::pdf_document2:
extra_dependencies: ["float"]
number_sections: false
toc: false
---
```{r, echo = FALSE}图书馆(Ggplot2)
数据(Mtcar)
名称(Mtcar)
### Heading 1
```{r figure-1,echo=FALSE, fig.cap = "Sample Graph 1"}(mtcar,aes(x=mpg,y=hp))+ )
geom_point()+ )
theme_classic()
To see another graph, please see figure \@ref(fig:figure-2)
\newpage
### Heading 2
```{r figure-2,echo=FALSE, fig.cap = "Sample Graph 2"}(mtcar,aes(x=mpg,y=carb))+ )
geom_point()+ )
theme_classic()
To see another graph, please see figure \@ref(fig:figure-1)我试图将@ref包含在\textcolor{}{}中,但是Latex删除交叉引用,只在编织的pdf文档中显示@ref(fig:figure-1)。
此外,我想把标题放在数字的顶部,而不是放在底部。我查看了Stackoverflow,用户建议使用floatrow包来控制标题的放置,但是我不能在floatrow包中使用floatrow。我使用文档中的浮动包来控制文档中的额外空间,方法是使用以下用Latex编写的代码:
\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
\expandafter\origfigure\expandafter[H]
} {
\endorigfigure
}(请帮助我整理这些问题:)
发布于 2022-02-27 15:29:40
我想出了我问题中提到的两个问题的解决办法。下面我向其他学生分享我对这两个问题的解决方案:
更改交叉引用颜色
我们不能使用Latex \textcolor{}{}来更改R中交叉引用的颜色。我的想法是在编写文档时将多个Latex命令与简单的单词混淆。
谢等人(2020)通过创建lua过滤器解决了这个问题。我打开了“记事本”,复制了书中的代码。我把文件保存为color-text.lua.为了方便读者,下面给出了代码:
Span = function(el)
color = el.attributes['color']
-- if no color attribute, return unchange
if color == nil then return el end
-- transform to <span style="color: red;"></span>
if FORMAT:match 'html' then
-- remove color attributes
el.attributes['color'] = nil
-- use style attribute instead
el.attributes['style'] = 'color: ' .. color .. ';'
-- return full span element
return el
elseif FORMAT:match 'latex' then
-- remove color attributes
el.attributes['color'] = nil
-- encapsulate in latex code
table.insert(
el.content, 1,
pandoc.RawInline('latex', '\\textcolor{'..color..'}{')
)
table.insert(
el.content,
pandoc.RawInline('latex', '}')
)
-- returns only span content
return el.content
else
-- for other format return unchanged
return el
end
end保存该文件后,我们需要在所需文档的YAML头中包含cold-text.lua。我们将通过修改YAML头文件来合并lua文件:
---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output:
bookdown::pdf_document2:
pandoc_args: ["--lua-filter=color-text.lua"]
number_sections: false
toc: false
---修改YAML标题后,可以通过以下方式更改交叉引用文本的字体颜色:
To see another graph, please see figure [\@ref(fig:figure-2)]{color="blue"}我们需要在方括号中写入交叉引用的文本,然后在{}内写入颜色参数。
更改标题的位置并控制额外的空白空间
如果要在pdf文档中更改标题和控件的位置以获得额外的空白,则需要在.tex文件中包括以下行
\usepackage{floatrow}
\usepackage[onehalfspacing]{setspace}
\floatsetup[figure]{capposition=top}
\floatplacement{figure}{H}将上述tex文件保存为caption_control.tex后,我们将将其包含在YAML头文件中:
---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output:
bookdown::pdf_document2:
pandoc_args: ["--lua-filter=color-text.lua"]
number_sections: false
toc: false
includes:
in_header: caption.control.tex
---https://stackoverflow.com/questions/71219125
复制相似问题