通过 LaTeX 使用 pandoc 转换为 PDF 时出现表格间距问题

2023-12-05

我面临着 R 中的问题texreg()似乎没有打破表格下方注释中的线条。此外,模型之间的边距也没有像发生的那样平等地扩展htmlreg()这给出了一个干净的结果。手动中断如\n或 HTML 标签不适用于“texreg”。有一个部分MichaelChirico 的解决方法,但必须改变texreg()函数,但当我们并排处理多个模型时,该方法似乎不考虑这种情况。

这是我正在使用的代码:

---
title: "Untitled"
author: "jaySf"
date: "13 Juni 2017"
output:
  pdf_document: default
  html_document: default
---

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

```{r results="asis"}
library(car)
lm1 <- lm(prestige ~ income, data=Duncan)
lm2 <- lm(prestige ~ education, data=Duncan)
lm3 <- lm(prestige ~ income + education, data=Duncan)

library(texreg)
texreg(list(lm1, lm2, lm3), custom.note = "Lorem ipsum dolor sit amet, <br>consetetur sadipscing 
       elitr, sed diam. %stars.") # for pdf output

htmlreg(list(lm1, lm2, lm3), custom.note = "Lorem ipsum dolor sit amet, <br>consetetur sadipscing 
       elitr, sed diam. %stars.") # for html output
```

这是输出:

ugly table

有人知道吗?任何帮助表示赞赏。

这里是生成的 LaTeX 代码:

\documentclass[]{article}
\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}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% 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
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
            pdftitle={Untitled},
            pdfauthor={jaySf},
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{{#1}}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{{#1}}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{{#1}}}
\newcommand{\ImportTok}[1]{{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{{#1}}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{{#1}}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{{#1}}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{{#1}}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{{#1}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{{#1}}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{{#1}}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{{#1}}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{{#1}}}}
\newcommand{\BuiltInTok}[1]{{#1}}
\newcommand{\ExtensionTok}[1]{{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{{#1}}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{{#1}}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
\usepackage{graphicx,grffile}
\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}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}
  \title{Untitled}
  \pretitle{\vspace{\droptitle}\centering\huge}
  \posttitle{\par}
  \author{jaySf}
  \preauthor{\centering\large\emph}
  \postauthor{\par}
  \predate{\centering\large\emph}
  \postdate{\par}
  \date{13 Juni 2017}


\begin{document}
\maketitle

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(car)}
\NormalTok{lm1 <-}\StringTok{ }\KeywordTok{lm}\NormalTok{(prestige ~}\StringTok{ }\NormalTok{income, }\DataTypeTok{data=}\NormalTok{Duncan)}
\NormalTok{lm2 <-}\StringTok{ }\KeywordTok{lm}\NormalTok{(prestige ~}\StringTok{ }\NormalTok{education, }\DataTypeTok{data=}\NormalTok{Duncan)}
\NormalTok{lm3 <-}\StringTok{ }\KeywordTok{lm}\NormalTok{(prestige ~}\StringTok{ }\NormalTok{income +}\StringTok{ }\NormalTok{education, }\DataTypeTok{data=}\NormalTok{Duncan)}

\KeywordTok{library}\NormalTok{(texreg)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Version:  1.36.23
## Date:     2017-03-03
## Author:   Philip Leifeld (University of Glasgow)
## 
## Please cite the JSS article in your publications -- see citation("texreg").
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{texreg}\NormalTok{(}\KeywordTok{list}\NormalTok{(lm1, lm2, lm3), }\DataTypeTok{custom.note =} \StringTok{"Lorem ipsum dolor sit amet, <br>consetetur sadipscing }
\StringTok{       elitr, sed diam. %stars."}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{table}
\begin{center}
\begin{tabular}{l c c c }
\hline
 & Model 1 & Model 2 & Model 3 \\
\hline
(Intercept) & $2.46$       & $0.28$       & $-6.06$      \\
            & $(5.19)$     & $(5.09)$     & $(4.27)$     \\
income      & $1.08^{***}$ &              & $0.60^{***}$ \\
            & $(0.11)$     &              & $(0.12)$     \\
education   &              & $0.90^{***}$ & $0.55^{***}$ \\
            &              & $(0.08)$     & $(0.10)$     \\
\hline
R$^2$       & 0.70         & 0.73         & 0.83         \\
Adj. R$^2$  & 0.69         & 0.72         & 0.82         \\
Num. obs.   & 45           & 45           & 45           \\
RMSE        & 17.40        & 16.69        & 13.37        \\
\hline
\multicolumn{4}{l}{\scriptsize{Lorem ipsum dolor sit amet, <br>consetetur sadipscing 
       elitr, sed diam. $^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$.}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}

\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{htmlreg}\NormalTok{(}\KeywordTok{list}\NormalTok{(lm1, lm2, lm3), }\DataTypeTok{custom.note =} \StringTok{"Lorem ipsum dolor sit amet, <br>consetetur sadipscing }
\StringTok{       elitr, sed diam. %stars."}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

Statistical models

Model 1

Model 2

Model 3

(Intercept)

2.46

0.28

-6.06

(5.19)

(5.09)

(4.27)

income

1.08***

0.60***

(0.11)

(0.12)

education

0.90***

0.55***

(0.08)

(0.10)

R2

0.70

0.73

0.83

Adj. R2

0.69

0.72

0.82

Num. obs.

45

45

45

RMSE

17.40

16.69

13.37

{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam.
\emph{\textbf{p \textless{} 0.001, }p \textless{} 0.01, }p \textless{}
0.05.}


\end{document}

在这里我很乐意引用伟大的我从 Fran 那里收到的答案:https://tex.stackexchange.com/.

据他说,定制注释以\multicolumn在 LaTeX 代码中。因此我们不能使用换行命令,例如par or \\。但我们可以通过以下方式实现自动换行\parbox。如果我们仍然想要自定义换行符,我们可以使用四个反斜杠\\\\。为了更好的格式化,我们使用\\vspace{2pt}。为了给系数和神更多的空间,我们可以添加\renewcommand\arraystretch{1.3}(默认为 1)在 R 块之前:

\renewcommand\arraystretch{1.3}  

```{r results="asis", echo = TRUE, comment = FALSE, message = FALSE}

library(texreg)
texreg(list(lm1, lm2, lm3), custom.note = "\\parbox{.4\\linewidth}
{\\vspace{2pt}Lorem ipsum dolor sit amet, consetetur sadipscing elitr, 
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna 
aliquyam. \\\\ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, 
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna 
aliquyam. \\\\ %stars.}")

```

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 LaTeX 使用 pandoc 转换为 PDF 时出现表格间距问题 的相关文章

随机推荐

  • Javascript 事件在平板电脑上不起作用?

    我在 ASP NET 3 5 中开发了一个 Web 应用程序 它消耗了大量的 javascript JQuery 事件 并且在 PC 的普通浏览器中正常工作 但我的客户说这些在tablet pc android 和 iPad 中不起作用 就
  • Jquery Mobile:多次更新表单

    好的 经过几个小时的困惑 我发现在 Jquery Mobile 元素上调用 page 只能工作一次 如果我想通过 AJAX 多次更新表单 该怎么办 update jQuery Mobile beta2 引入了create event tri
  • 如何模拟 do-while 循环?

    我需要在 Python 程序中模拟 do while 循环 不幸的是 下面的简单代码不起作用 list of ints 1 2 3 iterator list of ints iter element None while True if
  • 如何引用Microsoft.Office.Interop.Excel dll?

    我在 2006 年使用 MS VS 2005 开发了一个处理 Excel 表格的系统 现在 我无法在 MS VS 2012 中使用相同的参考 var app new Microsoft Office Interop Excel Applic
  • SQL删除清除表而不是出错

    我有一段 SQL 你会认为 无法编译 但它会从目标表中删除所有行 考虑这个设置 create table TableA ColumnA varchar 200 create table TableB ColumnB varchar 200
  • 如何创建复选框列表

    我正在尝试读取 xml 文件并填充QListWidget及其一些内容 每个条目都应该有一个复选框 在 Qt Designer 中 我创建了列表并添加了一个具有复选框的项目 方法是将项目添加到 listWidget 然后右键单击它并选择 编辑
  • SceneKit – 加载 HDR 或 EXR 光照环境没有效果

    我尝试加载 hdr文件以将其用作天空盒并使用其照明信息 这是我使用的代码 backgroundColor UIColor gray check if a default skybox is added let environment UII
  • 以编程方式删除 Lotus Notes 设计元素继承

    作为创建基本修订控制系统的一部分 我想以编程方式禁用 Lotus Notes 模板上的设计元素级别继承 到目前为止我已经尝试过以下方法 DXL 导出 ForceNoteFormat true XSLT 由于导入器中字段 上的验证问题而失败
  • 通过chrome扩展获取下载文件的绝对路径

    我正在开发一个 chrome 扩展 它可以从网页下载特定文件 我有一个 popup html 通过它我可以输入要下载的文件的名称 还有一个链接 历史记录 单击该链接我想打开一个新页面 其中包含指向以前下载的文件的链接 下载历史记录 我可以下
  • PHP 致命错误:在非对象上调用成员函数 Execute() [关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 当我执行此代码时 出现错误 PHP 致命错误 在非对象
  • 如何在 Scene Kit 中对同一场景使用多个摄像机

    我有 2 个彼此相邻的 SCNView 两者都应该显示相同的场景 但通过不同的摄像机 在我看来 场景套件使用该节点和节点层次结构中最高的相机 所以我尝试了类似的方法 leftSceneView scene rootNode addChild
  • 哪里可以下载 MotoDev Studio? [关闭]

    Closed 这个问题是无关 目前不接受答案 在新的摩托罗拉网站中 我找不到任何 MotoDev Studio 的链接 我去年用过 现在好像消失了 你知道我在哪里可以找到最后的版本吗 他们不再支持 MotoDev 工作室 这与收购Googl
  • Swift:如何使用 PREPROCESSOR Flags(如 `#if DEBUG`)来实现 API 密钥?

    In Objective C有时使用静态字符串常量定义备用 API 键很有用 例如 区分分析包的 RELEASE 和 DEBUG 键 如 MixPanel Flurry 或 Crashlytics if DEBUG static NSStr
  • laravel 在本地计算机上返回 json 字符串,但在 elastic beanstalk 实例上返回整数

    我在使用 aws mysql laravel 和 Angular 时遇到一个奇怪的问题 我有一个本地运行的 vagrant 实例 上面运行着我的应用程序和数据库 我在前端使用 Angular 因此当加载视图时 Angular 会请求接收用户
  • 您能解释一下这个嵌入式 MATLAB 函数错误吗?

    我在将值从 GUI 发送到 Simulink 模型中的嵌入式 MATLAB 函数 EMF 时遇到问题 我从 GUI 中的滑块获取该值 并将其发送到模型中的 EMF 块 我可以确认该值已从 GUI 正确传输到 Simulink 模块 因为我可
  • 在 Access 中为最终用户创建动态“复选框”查询

    用例场景 我有一个低收入居民的客户 这些居民可以填写带有一堆复选框的纸质表格 它有一个 教育 部分 GED 文凭 助理等 另一部分为 技能 暖通空调 管道等 雇主联系我的客户 例如要求他们所有接受过 HVAC 培训的居民都拥有 GED 现在
  • Varnish + nginx + ELB 499 响应

    我有 varnish 4 服务器使用 nginx 作为连接到 ELB 的反向代理 每隔 2 天左右 我的服务器就会停止响应 我会在 nginx access log 中看到 499 个响应 重启nginx即可解决问题 为什么我开始收到这些
  • 如何创建不可复制对象的元组

    我正在尝试创建一个不可复制对象的元组 当我有了复制构造函数时 我就可以构造元组 当它们被删除时 编译将失败 include
  • 如何在 Git 中提交并推送选定的文件(但不是全部)

    我有一个有两个分支的 git 存储库 develop and master 我主要工作于develop当文件准备好时 有时不太坚持这个确认 我将它们合并到master分支将它们投入生产 看看这张照片 所有这些文件都来自develop分支并被
  • 通过 LaTeX 使用 pandoc 转换为 PDF 时出现表格间距问题

    我面临着 R 中的问题texreg 似乎没有打破表格下方注释中的线条 此外 模型之间的边距也没有像发生的那样平等地扩展htmlreg 这给出了一个干净的结果 手动中断如 n或 HTML 标签不适用于 texreg 有一个部分MichaelC