1

我想更改 texreg 生成的表中的字体。我正在编织 RStudio 的 Rmarkdown 表,因此不能直接修改 LaTeX。

这是一个例子。标题、系数名称和一些结果都打印在 robots.txt 中。其他结果不是。我想让所有的数字都变成roboto或inconsolata。建议?

我还想制作表格笔记机器人。

---
title: "Untitled"
header-includes:
  - \usepackage{fontspec}
  - \setmonofont[Mapping=tex-text]{inconsolata}
  - \usepackage[sfdefault]{roboto}
  - \renewcommand{\familydefault}{\sfdefault}
output:
  pdf_document:
    latex_engine: xelatex
---

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

```{r, results='asis', echo=F}
model.1 <- lme(distance ~ age, data = Orthodont, random = ~ 1)
model.2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
texreg(list(model.1, model.2))
```

在此处输入图像描述

4

1 回答 1

0

我对在 LaTeX 中处理字体不够熟悉,无法给你一个完整的答案,但希望这会让你更接近你的目标。

基本思想是操纵 的输入/输出texreg来给你你想要的,因为texreg它本身缺乏这些能力。

在您的情况下,我认为您可以仅通过操作输入来完成所需的操作,但操作输出的方法是使用capture.output如下:

tbl = capture.output(texreg(list(model.1, model.2)))

并使用 regex/whatever 来修复那里的输出。

我只是texttt用来举例说明这种方法:

rename_coef = function(reg) {
  names(reg$coefficients$fixed) = 
    paste0('\\texttt{', names(reg$coefficients$fixed), '}')
  reg
}

model.1 <- rename_coef(lme(distance ~ age, data = Orthodont, random = ~ 1))
model.2 <- rename_coef(lme(distance ~ age + Sex, data = Orthodont, random = ~ 1))

texreg(list(model.1, model.2))

将获取要自定义的系数名称列字体:

# \begin{table}
# \begin{center}
# \begin{tabular}{l c c }
# \hline
#  & Model 1 & Model 2 \\
# \hline
# \texttt{(Intercept)} & $16.76^{***}$ & $17.71^{***}$ \\
#                      & $(0.80)$      & $(0.83)$      \\
# \texttt{age}         & $0.66^{***}$  & $0.66^{***}$  \\
#                      & $(0.06)$      & $(0.06)$      \\
# \texttt{SexFemale}   &               & $-2.32^{**}$  \\
#                      &               & $(0.76)$      \\
# \hline
# AIC                  & 455.00        & 447.51        \\
# BIC                  & 465.66        & 460.78        \\
# Log Likelihood       & -223.50       & -218.76       \\
# Num. obs.            & 108           & 108           \\
# Num. groups          & 27            & 27            \\
# \hline
# \multicolumn{3}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
# \end{tabular}
# \caption{Statistical models}
# \label{table:coefficients}
# \end{center}
# \end{table}

如果要操作表格注释的字体,请使用custom.note参数:

texreg(list(model.1, model.2), custom.note ='\\texttt{Block font note}')
于 2017-04-24T22:43:01.220 回答