【问题标题】:how to reduce space after drawing graphs in RMarkdown using tikz使用 tikz 在 RMarkdown 中绘制图形后如何减少空间
【发布时间】:2021-01-12 14:32:12
【问题描述】:

我正在写一个 RMarkdown 演示文稿,在一张特定的幻灯片中(新的小节,请参见下文)我有 5 个图表,然后空间太大。这不允许我在该幻灯片中写更多内容,并将文本移动到标题下方不需要的地方。如何减少那个空间?

---
title: name

author: name
        
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

# New section

## New subsection

\small
\justify
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

More text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text tex. 

\begin{tikzpicture}[>=triangle 45, font=\footnotesize]
\put(-3,-20){
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (1,0) {};
\draw[->,shorten >= 1pt] (T)--(Y);
}
\end{tikzpicture}


\begin{tikzpicture}[>=triangle 45, font=\footnotesize]
\put(45,7){
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (1,0) {};
\draw[<-,shorten >= 1pt] (T)--(Y);
}
\end{tikzpicture}

\begin{tikzpicture}[>=triangle 45, font=\footnotesize]
\put(94,62){
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (2,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={above:{U}}] (U) at (1,0.5) {};
\draw[->,shorten >= 1pt] (T)--(Y);
\draw[->,shorten >= 1pt] (U)--(T);
\draw[->,shorten >= 1pt] (U)--(Y);
}
\end{tikzpicture}

\begin{tikzpicture}[>=triangle 45, font=\footnotesize]
\put(169,116){
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (2,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={above:{U}}] (U) at (1,0.5) {};
\draw[<-,shorten >= 1pt] (T)--(Y);
\draw[->,shorten >= 1pt] (U)--(T);
\draw[->,shorten >= 1pt] (U)--(Y);
}
\end{tikzpicture}

\begin{tikzpicture}[>=triangle 45, font=\footnotesize]
\put(245,171){
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (2,0) {};
\node[fill,circle,inner sep=0pt,minimum size=5pt,label={above:{U}}] (U) at (1,0.5) {};
\draw[->,shorten >= 1pt] (U)--(T);
\draw[->,shorten >= 1pt] (U)--(Y);
}
\end{tikzpicture}

Finally, more text in here.

我的 header.tex 是:

\definecolor{mycolorlightblue}{RGB}{103,153,200}
\definecolor{mycolordarkblue}{RGB}{0,70,127}
% add packages
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{tcolorbox}
\usepackage{ragged2e}
% 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}
% define colour text
% \usebeamerfont{section title}\color{blue!70!green}\insertsection\par
% 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}}

【问题讨论】:

    标签: latex r-markdown tex tikz


    【解决方案1】:

    问题在于您使用的\put(94,62){...} 语法。这不会将图像放置在 tikzpicture 所在的位置,但会在整个框架中粉碎它们。

    相反,您可以让 tex 为您定位 tikzpictures:

    \small
    \justify
    Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
    
    More text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text tex. 
    
    
    \begin{tikzpicture}[>=triangle 45, font=\footnotesize]
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (1,0) {};
    \draw[->,shorten >= 1pt] (T)--(Y);
    \end{tikzpicture}%
    \begin{tikzpicture}[>=triangle 45, font=\footnotesize]
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (1,0) {};
    \draw[<-,shorten >= 1pt] (T)--(Y);
    \end{tikzpicture}%
    \begin{tikzpicture}[>=triangle 45, font=\footnotesize]
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (2,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={above:{U}}] (U) at (1,0.5) {};
    \draw[->,shorten >= 1pt] (T)--(Y);
    \draw[->,shorten >= 1pt] (U)--(T);
    \draw[->,shorten >= 1pt] (U)--(Y);
    \end{tikzpicture}%
    \begin{tikzpicture}[>=triangle 45, font=\footnotesize]
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (2,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={above:{U}}] (U) at (1,0.5) {};
    \draw[<-,shorten >= 1pt] (T)--(Y);
    \draw[->,shorten >= 1pt] (U)--(T);
    \draw[->,shorten >= 1pt] (U)--(Y);
    \end{tikzpicture}%
    \begin{tikzpicture}[>=triangle 45, font=\footnotesize]
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{T}}] (T) at (0,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={below:{Y}}] (Y) at (2,0) {};
    \node[fill,circle,inner sep=0pt,minimum size=5pt,label={above:{U}}] (U) at (1,0.5) {};
    \draw[->,shorten >= 1pt] (U)--(T);
    \draw[->,shorten >= 1pt] (U)--(Y);
    \end{tikzpicture}%
    

    【讨论】:

    • 谢谢你,但不幸的是仍然不适合我。如果我不使用 \put(94,62){...},我会得到一个低于另一个的图表,这不是我想要的。我正在使用 RMarkdown,所以我有 #New section ## New subsection 等,而不是你那里的 \begin{frame} \frametitle{New subsection}。
    • @DanielaRodrigues 您是否删除了空行,就像我的回答一样?
    • 我没有注意到这一点。现在正在运行,非常感谢!
    猜你喜欢
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    相关资源
    最近更新 更多