首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字幕的颜色变为fgcolor (编织,Rnw)

字幕的颜色变为fgcolor (编织,Rnw)
EN

Stack Overflow用户
提问于 2020-05-30 17:54:08
回答 1查看 61关注 0票数 0

当对Rnw文件使用captions时,在块内创建的字幕字体的颜色变为fgcolor。

此问题类似于knitr kable: Text color in PDF from RNW is grey。这个解决方案在这种情况下没有用处。

有没有办法解决这个问题?黑客函数(knit_hooks$set= myfunction)?怎么做?谢谢。

代码语言:javascript
复制
% Minimal.Rnw
\documentclass{tufte-book}
\begin{document}
Color of normal font is black.
<<fig.env='marginfigure',fig.cap="The color of the font of the caption is fgcolor">>=
plot(1:10)
@
\begin{marginfigure}
    \caption{This color is black.}
\end{marginfigure}
\end{document}

编辑我:

我发布了一个可工作的解决方案,以供将来参考。伯努瓦指出了关键的勾号fig.show='hide'。不幸的是,它没有编写图形环境。所以我创建了一个名为colorcaption的新钩子,它解决了这个问题。使用所需的颜色(blackredgreen等)调用此选项。

代码语言:javascript
复制
% Minimal.Rnw
\documentclass{tufte-book}
\begin{document}
<<echo=FALSE>>=
library(knitr)
knit_hooks$set(colorcaption = function(before, options, envir){
    ## Hacked from hook_plot_custom
    if (before) return() # run hook after the chunk
    ext = "pdf" #  original: options$fig.ext %n% dev2ext(options$dev)
    hook = knit_hooks$get('plot')
    ##
    n = options$fig.num
    if (n == 0L) n = options$fig.num = 1L # make sure fig.num is at least 1
    res = unlist(lapply(seq_len(n), function(i) {
        options$fig.cur = i
        hook(fig_path(ext, options, i), knitr:::reduce_plot_opts(options))
    }), use.names = FALSE)
    res <- paste(res, collapse = '')
    ## My hack. Put the color after the end of kframe
    sub("\\end{kframe}",paste0("\\end{kframe}\\color{",options$colorcaption, "}"),res,fixed=TRUE)
})
@
Color of normal font is black. 
<<colorcaption='red',fig.show='hide',fig.env='marginfigure',fig.cap="The color of the font of the caption is colorcaption",>>=
1:10
plot(1:10)
10:1
@
Hello
\begin{marginfigure}
    \caption{This color is black.}
\end{marginfigure}
\end{document}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-30 18:30:35

如果您的R代码块生成的绘图存储在figure文件夹中,这样做应该是您想要的结果:

代码语言:javascript
复制
\documentclass{tufte-book}
\begin{document}
Color of normal font is black.
<<test1, fig.show = 'hide'>>=
plot(1:10)
@

\begin{marginfigure}
\includegraphics[width = \textwidth]{figure/test1-1}
\caption{this is now the correct color}
\end{marginfigure}

\begin{marginfigure}
    \caption{This color is black.}
\end{marginfigure}
\end{document}

或者你可以在前言中(重新)定义fgcolor

代码语言:javascript
复制
\documentclass{tufte-book}
\definecolor{fgcolor}{RGB}{0,0,0}
\begin{document}
Color of normal font is black.
<<fig.env='marginfigure',fig.cap="The color of the font of the caption is fgcolor">>=
plot(1:10)
@
\begin{marginfigure}
    \caption{This color is black.}
\end{marginfigure}
\end{document}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62100744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档