Rmarkdown支持多个字幕吗?

时间:2017-05-18 13:46:50

标签: knitr r-markdown caption

我需要在每个图形下方和每个表格上方插入两个字幕。 一个标题是波兰语,第二个标题是英语。 在LaTeX中,这可以通过以下方式由bicaption包完成:

\usepackage{polski}
 \usepackage[english, polish]{babel} 
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[lang=english]{bicaption}

\begin{figure}[H]
    \includegraphics[width=0.5\textwidth]{Einrad}

    \bicaption{Polish caption here with special letters: ĄĆŹŚÓŁ}{English caption just below}

    \label{Fig:FIgBicycle}
\end{figure}

是否有可能在Rmarkdown中做同样的事情?我可以看到只有一个fig.cap=可用?

1 个答案:

答案 0 :(得分:0)

我无法完成从.Rmd到.pdf的这项工作。但是,我能够破解从.Rnw到.pdf的解决方案。修改source挂钩以将LaTeX \caption更改为\bicaption并使用块选项fig.cap = "polish caption}{English caption"

以下是一个示例.Rnw文件:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[english, polish]{babel}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[lang=english]{bicaption}

\title{Bicaptions}

\begin{document}

\maketitle

We will defind a hood to replace the {\tt caption} command with {\tt bicaption}
when the \LaTeX\ is rendered.

<<>>=
library(ggplot2)
library(knitr)

hook_source <- knit_hooks$get('source')
knit_hooks$set(source = function(x, options) {                
                   txt <- hook_source(x, options)
                   gsub("\\\\caption", "\\\\bicaption", txt)
                 }) 
@

\blindtext

<<eg_graphic, echo = FALSE, fig.cap = 'Polish caption here with special letters: ĄĆŹŚÓŁ }{English caption just below', fig.align = "center", fig.width = 3, fig.height = 3>>=
ggplot(mtcars) + aes(x = wt, y = mpg) + geom_point()
@

\Blindtext

\end{document}

输出如下:

enter image description here