如何删除标题和表格之间的空白? [英] How do you remove white space between title and table?

查看:61
本文介绍了如何删除标题和表格之间的空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也尝试在其他地方询问此问题,但是我无法删除表格标题和实际表格之间的空白.在我的常规rmarkdown文章中,不会发生这种情况,但是当我为演示文稿而扎弯时,它会产生这些奇怪的空白.有人知道为什么吗?

I tried asking this somewhere else as well, but I am having trouble removing the white space between the title of my table and the actual table. This doesn't happen when in my regular rmarkdown article, but when I knit to beamer for my presentation it produces these bizarre white spaces. Anyone know why?

mean.party.class <- dat3 %>%
  group_by(party2, class2) %>%
   filter (party2 !="Indep" & class != "IDK")%>%
  summarise_at(vars(DL, DU, RL, RU, L, U, D, R), funs(mean(., na.rm=TRUE)))

knitr::kable(mean.party.class, col.names=c("Party ID", "Class", "DL", "DU", "RL",   "RU",   "L", "U", "D" , "R"), digits=2,  caption = "Mean Trust Per Group (Party and Social Class Identity)", "latex", booktabs = T) %>%
 kable_styling( full_width = F, position = "left",  latex_options = "scale_down", bootstrap_options = c("striped", "hover")) %>% footnote(
   general = c("1. D= Democrat, R=Republican, L=Lower Class, U = Upper Class; ", "2. Independents dropped")) %>% row_spec(0,bold=TRUE)

这里是一个示例

---
title: "Example"
author: "Its me"
date: "6/12/2020"
always_allow_html: true
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{adjustbox}
- \usepackage{caption} \captionsetup[table]{skip=0pt}
- \usepackage[font=small,skip=0pt]{caption}
- \usepackage{tikz}
- \usepackage{float}
- \usetikzlibrary{arrows,shapes,positioning}


output:
  beamer_presentation:
    theme: "Berkeley"
    colortheme: "dolphin"
    fonttheme: "structurebold"
    slide_level: 2 
    #incremental: true
---

```{r}
setwd("~/Google Drive/UC Davis /R stuff")
```

```{r, include=FALSE}
library(rticles)
library(kableExtra)
library(knitr)
library(plyr)
library(dplyr)
library(gdata)
library(ggplot2)
library(MASS)
library(corrplot)
library(haven)
library(factoextra)
library(ggplot2)
library(ggrepel)
library(viridis)
library(lattice)
library(optiscale)
library(acepack)
library(psych)
library(smacof)
library(MCMCpack)
library(basicspace)
library(boot)
library(pscl)
library(wnominate)
library(RColorBrewer)
library(sjPlot)
```

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

```{r, include= FALSE}
#load cars
data("mtcars")
head(mtcars, 2)
```

```{r, include= FALSE}
mean.mpg <- mtcars %>%
  summarise_at(vars(mpg), funs(mean(., na.rm=TRUE)))
```

## there it is
```{r}
knitr::kable(mean.mpg, col.names=c("mpg"), digits=2,  caption = "This is a table", "latex", booktabs = T, escape=F) %>%
 kable_styling(full_width = T, position = "left", latex_options = "scale_down", bootstrap_options = c("striped", "hover")) %>% footnote(
   general = c("1. test 1", "2. test 2"))%>%
  row_spec(0,bold=TRUE)
```

推荐答案

如果在标题中添加 keep_tex:true ,则可以编辑生成的.tex文件,以消除造成多余空间的多种原因:

If you add keep_tex: true to your header you can edit the resulting .tex file to remove the multiple causes of the additional space:

  • 删除桌子周围不必要的且通常有害的 \ resizebox {\ linewidth} {!} {...}

删除 caption 程序包(该程序不必要地多次加载)

remove the caption package (which is unnecessarily loaded multiple times)

删除 parskip

\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[ignorenonframetext,]{beamer}
\usepackage{pgfpages}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbolsempty
% Prevent slide breaks in the middle of a paragraph:
\widowpenalties 1 10000
\raggedbottom
\setbeamertemplate{part page}{
\centering
\begin{beamercolorbox}[sep=16pt,center]{part title}
  \usebeamerfont{part title}\insertpart\par
\end{beamercolorbox}
}
\setbeamertemplate{section page}{
\centering
\begin{beamercolorbox}[sep=12pt,center]{part title}
  \usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
\centering
\begin{beamercolorbox}[sep=8pt,center]{part title}
  \usebeamerfont{subsection title}\insertsubsection\par
\end{beamercolorbox}
}
\AtBeginPart{
  \frame{\partpage}
}
\AtBeginSection{
  \ifbibliography
  \else
    \frame{\sectionpage}
  \fi
}
\AtBeginSubsection{
  \frame{\subsectionpage}
}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provides euro and other symbols
\else % if luatex or xelatex
  \usepackage{unicode-math}
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
\usetheme[]{Berkeley}
\usecolortheme{dolphin}
\usefonttheme{structurebold}
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\IfFileExists{parskip.sty}{%
%\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\usepackage{hyperref}
\hypersetup{
            pdftitle={Example},
            pdfauthor={Its me},
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\newif\ifbibliography
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}

% set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother

\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{adjustbox}
%\usepackage{caption}

%\captionsetup[table]{skip=0pt}
%\usepackage[font=small,skip=0pt]{caption}
\usepackage{tikz}
\usepackage{float}
\usetikzlibrary{arrows,shapes,positioning}

\title{Example}
\author{Its me}
\date{6/12/2020}

\begin{document}
\frame{\titlepage}

\begin{frame}{there it is}
\protect\hypertarget{there-it-is}{}

\begin{table}

\caption{\label{tab:unnamed-chunk-4}This is a table}
%\resizebox{\linewidth}{!}{
\begin{tabu} to \linewidth {>{\raggedleft}X}
\toprule
\textbf{mpg}\\
\midrule
20.09\\
\bottomrule
\multicolumn{1}{l}{\textit{Note: }}\\
\multicolumn{1}{l}{1. test 1}\\
\multicolumn{1}{l}{2. test 2}\\
\end{tabu}
%}
\end{table}

\end{frame}

\end{document}

(我会远离 tabu ,而使用普通表)

(I would stay away from tabu and use a normal table instead)

这篇关于如何删除标题和表格之间的空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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