微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从RMarkdown调用.tex中的特定代码?

如何解决如何从RMarkdown调用.tex中的特定代码?

我正在RMarkdown中创建演示文稿,并且具有下面的LaTeX代码生成图形:

\begin{picturegraph}[>=triangle 45,font=\footnotesize]
\node[fill,rectangle,inner sep=0pt,minimum size=5pt,label={right:{S}}] (S) at (4,2.66) {};
\node[fill,circle,label={below:{X}}] (X) at (0,0) {};
\node[fill,label={below:{Y}}] (Y) at (6,label={above:{Z}}] (Z) at (3,2) {};
\draw[->,shorten >= 1pt] (X)--(Y);
\draw[->,shorten >= 1pt] (Z)--(X);
\draw[->,shorten >= 1pt] (Z)--(Y);
\draw[->,shorten >= 1pt] (S)--(Z);
\draw[<->,dashed,shorten >= 1pt] (X) to[bend left=45] (Z);
\draw[<->,shorten >= 1pt] (X) to[bend left=30] (Y);
\end{picturegraph}

如果我将此代码放在RMarkdown脚本的想要的部分中,它将无法正常工作。

我想我可以将这段代码放入.tex文件中,然后从RMarkdown脚本中将该代码重新调用。在确保将其放入我想要的特定部分时,我该怎么做?

这是我的RMarkdown脚本:

---
title: |
    | ##title**

author: |
        | name
        | email
        |
        
date: "`r format(Sys.time(),'%d %B %Y')`"

output:
  beamer_presentation:
    theme: Szeged
    slide_level: 2
    includes:
      in_header: header.tex

linkcolor: false
---

```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```


# Outline

## Outline

1. Item 1
2. Item 2
3. Item 3

# Introduction

## First subsection

This is an example of a graph:

(I want to insert the graph here)


## Second subsection

Text

还有我的header.tex:

\definecolor{mycolorlightblue}{RGB}{103,153,200}
\definecolor{mycolordarkblue}{RGB}{0,70,127}
% remove 2nd section from header
\makeatletter
\beamer@theme@subsectionfalse
\makeatother
% change colour of lines
\setbeamercolor{separation line}{bg=mycolorlightblue}
% text title
\setbeamercolor{title}{fg=mycolordarkblue}
\setbeamercolor{frametitle}{fg=mycolordarkblue}
% text colour
\setbeamercolor{frametitle}{fg=mycolordarkblue}
% item colour
\setbeamercolor{structure}{fg=mycolordarkblue}
% no header or footer on first page
\thispagestyle{empty}
% remove title slides at beginning of sections
\AtBeginSection{}
% add page counter to the footer
\setbeamertemplate{footline}[frame number]
% logo of my university
\titlegraphic{%
  \begin{picture}(0,0)
    \put(155,0){\makeBox(0,0)[rt]{\includegraphics[]{ALL-ICONS.png}}}
  \end{picture}}

解决方法

几个问题:

  • picturegraph替换为tikzpicture
  • 加载丢失的tikz
  • 加载缺少的arrows lib
---
title: |
    | ##title**

author: |
        | name
        | email
        |
        
date: "`r format(Sys.time(),'%d %B %Y')`"

output:
  beamer_presentation:
    theme: Szeged
    slide_level: 2
    includes:
      in_header: header.tex
    keep_tex: true

linkcolor: false
---

```{r setup,include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```


# Outline

## Outline

1. Item 1
2. Item 2
3. Item 3

# Introduction

## First subsection

This is an example of a graph:

(I want to insert the graph here)


## Second subsection

Text

\begin{tikzpicture}[>=triangle 45,font=\footnotesize]
\node[fill,rectangle,inner sep=0pt,minimum size=5pt,label={right:{S}}] (S) at (4,2.66) {};
\node[fill,circle,label={below:{X}}] (X) at (0,0) {};
\node[fill,label={below:{Y}}] (Y) at (6,label={above:{Z}}] (Z) at (3,2) {};
\draw[->,shorten >= 1pt] (X)--(Y);
\draw[->,shorten >= 1pt] (Z)--(X);
\draw[->,shorten >= 1pt] (Z)--(Y);
\draw[->,shorten >= 1pt] (S)--(Z);
\draw[<->,dashed,shorten >= 1pt] (X) to[bend left=45] (Z);
\draw[<->,shorten >= 1pt] (X) to[bend left=30] (Y);
\end{tikzpicture}

并添加到header.tex

\usepackage{tikz}
\usetikzlibrary{arrows}

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。