Put figure directly into Knitr document (without saving file of it in folder)

前端 未结 1 402
遥遥无期
遥遥无期 2021-01-21 12:01

I am creating a document called test.Rnw in RStudio, with a MWE as follows:

\\documentclass[12pt,english,nohyper]{tufte-handout}
\\usepackage{tabularx}
\\usepack         


        
相关标签:
1条回答
  • 2021-01-21 12:44

    To change the color of the caption text can be done within LaTeX by setting \color within the \setcaptionfont environment to black (Line 8 of code.)

    With your example:

    \documentclass[nohyper]{tufte-handout}
    \usepackage{tabularx} 
    \usepackage{longtable}
    
    \setcaptionfont{% changes caption font characteristics
      \normalfont\footnotesize
      \color{black}% <-- set color here
    }
    
    \begin{document}
    
    <<setup, echo=FALSE>>=
    library(knitr)
    library(xtable)
    library(ggplot2)
    # Specify directory for figure output in a temporary directory
    temppath <- tempdir()
    opts_chunk$set(fig.path = temppath)
    @
    
    <<diamondData, echo=FALSE, fig.env = "marginfigure", out.width="0.95\\linewidth",
    fig.cap = "The diamond dataset has varibles depth and price.",fig.lp="mar:">>=
    print(qplot(depth,price,data=diamonds))
    @
    
    
    
    <<echo=FALSE,results='asis'>>=
    myDF <- data.frame(a = rnorm(1:10), b = letters[1:10])
    print(xtable(myDF, caption= 'This data frame shows ten random variables from the
    distribution and a corresponding letter', label='tab:dataFrame'),
     floating = FALSE, tabular.environment = "longtable", include.rownames=FALSE)
    @
    
    Figure \ref{mar:diamondData} shows the diamonds data set, with the
    variables price and depth.Table \ref{tab:dataFrame} shows letters a through j
    corresponding to a random variable from a normal distribution.
    
    \end{document}
    

    EDIT: Have changed the global options for the figure directory and have removed the line where the figure directory was specifically moved to the trash based on comments.

    0 讨论(0)
提交回复
热议问题