【问题标题】:Is Rmarkdown supporting multiple captions?Rmarkdown 是否支持多个字幕?
【发布时间】:2017-05-18 13:46:49
【问题描述】:

我需要在每个图下方和每个表格上方插入两个标题。 一个字幕是波兰语,第二个字幕是英语。 在 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= 可用?

【问题讨论】:

    标签: knitr r-markdown caption


    【解决方案1】:

    从 .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}
    

    输出如下所示:

    【讨论】:

    • 感谢您的详细解答。不幸的是,当我尝试编译您的文档时,由于某种原因,我没有看到任何图像(尽管编译过程中没有错误)。此外,我注意到,在您附加的打印屏幕上,Figure (Rysunek) 只有波兰语名称,但在下一行,只有标题文本,没有名称“Figure”。这是('Rysunek' 和下一行'Figure')它在 LaTeX 中的工作方式。
    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多