删除 R 生成的图和 Rtex 文件中的标题之间的 space

Removing the space between a plot generated by R and the caption in an Rtex file

我正在尝试编辑 Rtex 文件并创建绘图。我在下面有一个情节,它确实可以编译。但是,标题下方有一个空白的白色space。我不知道如何删除它。我试图寻找解决方案但无济于事:

我运行的代码以及输出如下所示。如果有人能帮助我,我将不胜感激。我也试过 trimmws() 函数,但它给出了以下错误:

## "Error in mysub(paste0("^", whitespace, "+"), x):  argument"x" is missing, with no default."

\documentclass[a4paper,11pt]{article}

%Packages
\usepackage[justification=centering]{caption}
\usepackage{blindtext}
\begin{document}
\title{F-distribution}
\maketitle
\section{Diagram showing the $F$-distribution for a selected pair of values of the degree of freedom}
\blindtext
\begin{figure}[h!]
<<echo=FALSE, cache=TRUE, fig.width=5, fig.height=5>>=
curve(df(x, df1=20, df2=20))
@
\caption{Hi}
\end{figure}
\blindtext
\blindtext
\end{document}

您的图像周围确实有很多白色 space。您可以使用此快速技巧将标题进一步向上移动:

\documentclass[a4paper,11pt]{article}

%Packages
\usepackage[justification=centering]{caption}
\usepackage{blindtext}
\begin{document}
\title{F-distribution}
\maketitle
\section{Diagram showing the $F$-distribution for a selected pair of values of the degree of freedom}
\blindtext
\begin{figure}[h!]
<<echo=FALSE, cache=TRUE, fig.width=5, fig.height=5>>=
curve(df(x, df1=20, df2=20))
@
\vskip-1cm
\caption{Hi}
\end{figure}
\blindtext
\blindtext
\end{document}