我正在写论文,想在 Rmarkdown 中包含几个表格。第一个表格很长,包含几个表示回归参数的 LaTeX 符号$\beta$
。行似乎有点挤,所以我使用 扩展了行之间的空间\renewcommand{\arraystretch}{1.3}
。一切都很正常,直到我尝试\renewcommand{\arraystretch}{1.3}
在第二个表格中使用。LaTeX 错误是,\caption outside float
所以我以为问题出在标题上。我终于弄清楚了,一旦我\renewcommand{\arraystretch}{1.3}
从第二个表格中删除 ,Rmarkdown 文件就会完美地结合在一起。我附上了一个来自 Rmarkdown 的例子。有人知道为什么使用\renewcommand{\arraystretch}{1.3}
两次不起作用吗?还有其他方法可以在行之间添加垂直空间吗?谢谢 <3
test.Rmd(整个文件)
---
title: "Real life data"
author: "Julie Berg"
date: "`r Sys.Date()`"
header-includes:
- \usepackage{tikz}
- \usetikzlibrary{automata, positioning, arrows}
- \usepackage{graphics}
- \usepackage{natbib}
output:
pdf_document:
toc: true
number_sections: true
extra_dependencies: ["bbm"]
papersize: a5
---
```{r setup, include=FALSE, echo=FALSE, warning=FALSE, message=FALSE}
rm(list=ls())
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE, out.width = "100%")
library(INLA)
library(survival)
library(mstate)
library(tidyverse)
library(patchwork)
library(dplyr)
library(ggplot2)
library(survival)
library(survminer)
```
# first table
\begin{table}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ c|cccc }
& mean & 0.025quant & 0.975quant & mode \\
\hline
$\beta_0^{52}$ & 1 & 1 & 1 & 1 \\
$\beta_0^{25}$ & 2 & 2 & 2 & 2 \\
$\beta_0^{21}$ & 3 & 3 & 3 & 3 \\
$\beta^{52}_{\text{Age}}$ & 4 & 4 & 4 & 4 \\
$\beta^{25}_{\text{Age}}$ & 5 & 5 & 5 & 5 \\
$\beta^{21}_{\text{Age}}$ & 6 & 6 & 6 & 6 \\
$\beta^{52}_{\text{Gen}}$ & 7 & 7 & 7 & 7 \\
$\beta^{25}_{\text{Gen}}$ & 8 & 8 & 8 & 8 \\
$\beta^{21}_{\text{Gen}}$ & 9 & 9 & 9 & 9 \\
$\beta^{52}_{\text{Mass}}$ & 10 & 10 & 10 & 10\\
$\beta^{25}_{\text{Mass}}$ & 11 & 11 & 11 & 11\\
$\beta^{21}_{\text{Mass}}$ & 12 & 12 & 12 & 12\\
$\beta^{52}_{\text{res}}$ & 13 & 13 & 13 & 13 \\
$\beta^{25}_{\text{res}}$ & 14 & 14 & 14 & 14 \\
$\beta^{21}_{\text{res}}$ & 15 & 15 & 15 & 15\\
$\alpha_{52}$ & 16 & 16 & 16 & 16 \\
$\alpha_{25}$ & 17 & 17 & 17 & 17\\
$\alpha_{21}$ & 18 & 18 & 18 & 18\\
\end{tabular}
\caption{Estimated parameter values using all Weibull baseline models.}
\label{Tab:estimatesWeib}
\end{table}
# second table
\begin{table}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ c|cccc }
& mean & 0.025quant & 0.975quant & mode \\
\hline
$\beta_0^{52}$ & 1 & 1 & 1 & 1 \\
$\beta_0^{25}$ & 2 & 2 & 2 & 2 \\
$\beta_0^{21}$ & 3 & 3 & 3 & 3 \\
$\beta^{52}_{\text{Age}}$ & 4 & 4 & 4 & 4 \\
$\beta^{25}_{\text{Age}}$ & 5 & 5 & 5 & 5 \\
$\beta^{21}_{\text{Age}}$ & 6 & 6 & 6 & 6 \\
$\beta^{52}_{\text{Gen}}$ & 7 & 7 & 7 & 7 \\
$\beta^{25}_{\text{Gen}}$ & 8 & 8 & 8 & 8 \\
$\beta^{21}_{\text{Gen}}$ & 9 & 9 & 9 & 9 \\
$\beta^{52}_{\text{Mass}}$ & 10 & 10 & 10 & 10\\
$\beta^{25}_{\text{Mass}}$ & 11 & 11 & 11 & 11\\
$\beta^{21}_{\text{Mass}}$ & 12 & 12 & 12 & 12\\
$\beta^{52}_{\text{res}}$ & 13 & 13 & 13 & 13 \\
$\beta^{25}_{\text{res}}$ & 14 & 14 & 14 & 14 \\
$\beta^{21}_{\text{res}}$ & 15 & 15 & 15 & 15\\
$\alpha_{52}$ & 16 & 16 & 16 & 16 \\
$\alpha_{25}$ & 17 & 17 & 17 & 17\\
$\alpha_{21}$ & 18 & 18 & 18 & 18\\
\end{tabular}
\caption{Estimated parameter values using an Exp baseline model.}
\label{Tab:estimatesExp}
\end{table}
生成的 .tex 文件
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
a5paper,
]{article}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\usepackage{amssymb}
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Real life data},
pdfauthor={Julie Berg},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{tikz}
\usetikzlibrary{automata, positioning, arrows}
\usepackage{graphics}
\usepackage{natbib}
\usepackage{bbm}
\ifluatex
\usepackage{selnolig} % disable illegal ligatures
\fi
\title{Real life data}
\author{Julie Berg}
\date{2022-01-26}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\hypertarget{first-table}{%
\section{first table}\label{first-table}}
\begin{table}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ c|cccc }
& mean & 0.025quant & 0.975quant & mode \\
\hline
$\beta_0^{52}$ & 1 & 1 & 1 & 1 \\
$\beta_0^{25}$ & 2 & 2 & 2 & 2 \\
$\beta_0^{21}$ & 3 & 3 & 3 & 3 \\
$\beta^{52}_{\text{Age}}$ & 4 & 4 & 4 & 4 \\
$\beta^{25}_{\text{Age}}$ & 5 & 5 & 5 & 5 \\
$\beta^{21}_{\text{Age}}$ & 6 & 6 & 6 & 6 \\
$\beta^{52}_{\text{Gen}}$ & 7 & 7 & 7 & 7 \\
$\beta^{25}_{\text{Gen}}$ & 8 & 8 & 8 & 8 \\
$\beta^{21}_{\text{Gen}}$ & 9 & 9 & 9 & 9 \\
$\beta^{52}_{\text{Mass}}$ & 10 & 10 & 10 & 10\\
$\beta^{25}_{\text{Mass}}$ & 11 & 11 & 11 & 11\\
$\beta^{21}_{\text{Mass}}$ & 12 & 12 & 12 & 12\\
$\beta^{52}_{\text{res}}$ & 13 & 13 & 13 & 13 \\
$\beta^{25}_{\text{res}}$ & 14 & 14 & 14 & 14 \\
$\beta^{21}_{\text{res}}$ & 15 & 15 & 15 & 15\\
$\alpha_{52}$ & 16 & 16 & 16 & 16 \\
$\alpha_{25}$ & 17 & 17 & 17 & 17\\
$\alpha_{21}$ & 18 & 18 & 18 & 18\\
\end{tabular}
\caption{Estimated parameter values using all Weibull baseline models.}
\label{Tab:estimatesWeib}
\end{table}
\hypertarget{second-table}{%
\section{second table}\label{second-table}}
\textbackslash begin\{table\} \centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{ c|cccc }
& mean & 0.025quant & 0.975quant & mode \\
\hline
$\beta_0^{52}$ & 1 & 1 & 1 & 1 \\
$\beta_0^{25}$ & 2 & 2 & 2 & 2 \\
$\beta_0^{21}$ & 3 & 3 & 3 & 3 \\
$\beta^{52}_{\text{Age}}$ & 4 & 4 & 4 & 4 \\
$\beta^{25}_{\text{Age}}$ & 5 & 5 & 5 & 5 \\
$\beta^{21}_{\text{Age}}$ & 6 & 6 & 6 & 6 \\
$\beta^{52}_{\text{Gen}}$ & 7 & 7 & 7 & 7 \\
$\beta^{25}_{\text{Gen}}$ & 8 & 8 & 8 & 8 \\
$\beta^{21}_{\text{Gen}}$ & 9 & 9 & 9 & 9 \\
$\beta^{52}_{\text{Mass}}$ & 10 & 10 & 10 & 10\\
$\beta^{25}_{\text{Mass}}$ & 11 & 11 & 11 & 11\\
$\beta^{21}_{\text{Mass}}$ & 12 & 12 & 12 & 12\\
$\beta^{52}_{\text{res}}$ & 13 & 13 & 13 & 13 \\
$\beta^{25}_{\text{res}}$ & 14 & 14 & 14 & 14 \\
$\beta^{21}_{\text{res}}$ & 15 & 15 & 15 & 15\\
$\alpha_{52}$ & 16 & 16 & 16 & 16 \\
$\alpha_{25}$ & 17 & 17 & 17 & 17\\
$\alpha_{21}$ & 18 & 18 & 18 & 18\\
\end{tabular}
\caption{Estimated parameter values using an Exp baseline model.}
\label{Tab:estimatesExp}
\textbackslash end\{table\}
\end{document}
答案1
答案来自一位没有 stackexchange 用户的朋友,因此我将替他回答:
“放在第一个表环境之外,它应该会延伸两个表而不会出现错误消息。那么第二个表\renewcommand{\arraystretch}{1.3}
就不需要第二个了”\renewcommand{\arraystretch}{1.3}
这很完美!我假设所有后续表格都会被拉伸,但就我而言这并不重要,因为这是最后一章表格。