首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将预订导出为pdf时,保持模型汇总表的位置

将预订导出为pdf时,保持模型汇总表的位置
EN

Stack Overflow用户
提问于 2022-07-04 10:25:34
回答 1查看 67关注 0票数 1

我正在写一份预订文件,在这里我想占据数字和表格的位置。这在大多数情况下正常工作,除非使用modelsummary

我试着创建一个有用的例子。我的文档如下所示(除了使用“”而不是通常的符号来启动代码--我不知道是否有更好的方法来说明这一点)

代码语言:javascript
复制
---
title: "Example:  \nExample 123"
subtitle: "Working Paper"
author: "Me"
output: 
  bookdown::pdf_document2:
    fig_caption: yes
    df_print: paged
    keep_md: true
bibliography: library.bib
floatsintext: yes
header-includes:  \usepackage{xcolor} \usepackage{float}
linestretch: 1.5
graphics: yes
---

'''{r packages, echo = FALSE, results = FALSE, message = FALSE, warning = FALSE}
library(tidyverse)
library(kableExtra)
library(sf)
library(expss)
library(modelsummary)
library(fixest)
'''

# Introduction

This is my introduction.


# Analysis

This is my analysis:

## First part

Here is my first part

## Second part

Here is my second part

''' {r regression1, fig.cap = "Regression 1", echo = F, fig.pos = "H", fig.align='center'}

regression1 <- feols(mpg ~ cyl | drat, mtcars) 


modelsummary(regression1, coef_omit = "Int", stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), gof_omit = "IC$|Lik.|RMSE|Std.Errors", gof_map = tribble(
  ~raw,        ~clean,          ~fmt,
  "nobs",      "N",             0,
  "r.squared", "R2",            2,
  "adj.r.squared", "R2 Adj.", 2,
  "r2.within",                 "R2 Within",          2,
  "r2.within.adjusted",        "R2 Within Adj.",     2
  ), title = "Regression 1") %>% footnote(general = "ABC", threeparttable = TRUE)
'''

## Third part

The analysis continues.


''' {r regression2, out.extra='', fig.cap = "Regression 2", echo = F, fig.pos = "H", fig.align='center'}


regression2 <- feols(mpg ~ cyl | csw(vs + am, vs^am), mtcars) 

names(regression2) <- c("Model 1", "Model 2")

modelsummary(regression2, coef_omit = "Int", stars = c("***" = 0.01, "**" = 0.05, "*" = 0.1), gof_omit = "IC$|Lik.|RMSE|Std.Errors", coef_rename = c("mpg" = "MPG", "cyl" = "CYL"), gof_map = tribble(
  ~raw,        ~clean,          ~fmt,
  "nobs",      "N",             0,
  "FE: country", "Country fixed effects", 0,
  "FE: year", "Year fixed effects", 0,
  "FE: country^year", "Country-year fixed effects", 0,
  "r.squared", "R2",            2,
  "adj.r.squared", "R2 Adj.", 2,
  "r2.within",                 "R2 Within",          2,
  "r2.within.adjusted",        "R2 Within Adj.",     2
  ), title = "Regression 2") %>% footnote(general = "ABC", threeparttable = TRUE)
'''

在PDF中,第二次回归表列于第2.2 -第二部分,而不是在2.3以下。-第三部分,将其放在减价文件中。其他数字和表格没有出现这种情况。如何保持modelsummary表的位置?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-04 13:13:40

我找到了一个解决方案:将模型摘要输出设置为output = "kableExtra" (这可能是不必要的),并在代码末尾添加%>% kable_styling(latex_options = c("HOLD_position"))

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72855259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档