LaTeX中由tikzDevice和ggplot2生成的标题和图形之间的空白太多 [英] Too much white space between caption and figure produced by tikzDevice and ggplot2 in LaTeX

查看:989
本文介绍了LaTeX中由tikzDevice和ggplot2生成的标题和图形之间的空白太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用R的 ggplot2 tikzDevice 包生成图形,并将它们引入 LaTeX 文档,但是我正在努力处理图形和标题之间的空白区域,正如您可以看到的,如果您比较图像(我手动突出显示了空格更清晰):

I'm currently using R's ggplot2 and tikzDevice packages to produce graphics and introduce them in LaTeX documents, but I'm struggling with the resulting big white spaces between the figures and the captions, as you can see if you compare the images (I've manually highlighted the spaces to make it clearer):


这是我的MWE:

R代码:

The R code:

library(ggplot2)
library(tikzDevice)

set.seed(1)
x <- rnorm(200)

tikz(file = "Rplots.tex", width = 4, height = 4)
qplot(x, geom = "histogram")
dev.off()

和LaTe X代码:

and the LaTeX code:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{figure}
\centering
\include{Rplots}
\caption{\texttt{ggplot2} plot.}
\end{figure}

\begin{figure}
\centering
\begin{tikzpicture}[scale=3]
    \clip (-0.1,-0.2)
    rectangle (1.8,1.2);
    \draw[step=.25cm,gray,very thin]
    (-1.4,-1.4) grid (3.4,3.4);
    \draw (-1.5,0) -- (2.5,0);
    \draw (0,-1.5) -- (0,1.5);
    \draw (0,0) circle (1cm);
    \filldraw[fill=green!20!white,
    draw=green!50!black]
    (0,0) -- (3mm,0mm)
    arc (0:30:3mm) -- cycle;
\end{tikzpicture}
\caption{\texttt{tikz} plot.}
\end{figure}

\end{document}

我想知道如何摆脱字幕和图形之间的巨大空间 ggplot2

I'd like to know how to get rid of the great space between the caption and the figure via ggplot2.

PS。 R版本:3.2.3, ggplot2 版本:2.1.0, tikzDevice 版本:0.10-1。我从Tobias Oetiker的 LaTeX 2e的简短介绍,版本5.05,第116页获取了第二个图的代码。

PS. R version: 3.2.3, ggplot2 version: 2.1.0, tikzDevice version: 0.10-1. I've taken the code for the second plot from Tobias Oetiker's The Not so Short Introduction to LaTeX 2e, version 5.05, page 116.

推荐答案

听起来更像是一个LaTeX问题;我认为调整空间的标准方法是设置 \abovecaptionskip

it sounds more like a LaTeX question; I think the standard way to tweak the space is to set \abovecaptionskip

\documentclass{article}
\usepackage{tikz}
\setlength{\abovecaptionskip}{-15pt} 
\begin{document}

\begin{figure}
\centering
\include{Rplots}
\caption{\texttt{ggplot2} plot.}
\end{figure}

\end{document}

这篇关于LaTeX中由tikzDevice和ggplot2生成的标题和图形之间的空白太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆