!非法计量单位(已插入pt)PDF编织错误

时间:2019-07-15 21:27:12

标签: r pdf latex

我正在尝试在RStudio中将报告编织为PDF。到目前为止,我的代码可以正常工作(我一直在逐块进行测试),直到到达下面的块为止:

## HCT-CI

```{r}
summaryTable(y=wdata$HCTCI.score, table.title="HCT-CI Raw Score",     y.labels="Number of Readmissions")

summaryTable(y=wdata$HCTCI.score, table.title="Readmissions",     freq.tab=T, y.name="HCT-CI Raw Score")

summaryTable(y=wdata$HCTCI.3cat, table.title="HCT-CI Score (3     Groups)", caption_heading="Note:", caption="1: Score=0; 2: Score=1-2;     3: Score=3+", freq.tab=T, y.labels=c("0", "1-2", "3+"))
```

\pagebreak

我的目标是成功生成PDF格式的输出。

与我在所有其他块中使用的功能和格式相同。当我自己运行该块时,它也可以工作。我已经在Google和其他stackoverflow帖子中查找了该问题,但是由于它们都使用HTML或其他语言,因此很难应用其解决方案。

我的完整报告看起来像这样(为简洁起见,删除了一些块):

文档开始

---
title: 
- \vspace{2in}Analysis for Study$\colon$ Readmissions
subtitle: 
- \vspace{.2in}\emph{`r format(Sys.time(), '%d %B, %Y')`}
author:
- \emph{PI$\colon$ Name}
- \emph{College}
- \vspace{.5in}\emph{Author}
- \emph{Position}
- \emph{email}
date:
- \vspace{4in}
header-includes:
- \usepackage{fancyhdr}
- \usepackage{titling}
- \usepackage{caption}
- \fancyhead[L]{\includegraphics[width=2cm]{pic.png}}
- \fancyhead[R]{\includegraphics[width=4cm]{pic.png}}
- \fancyfoot[C]{Department}
- \fancypagestyle{plain}{\pagestyle{fancy}}
geometry: left=.5in,right=.5in,top=1in,bottom=1in
mainfont: Times New Roman
output: 
  pdf_document: 
    keep_tex: true
    highlight: tango
    toc: true 
    toc_depth: 4
    number_sections: true
    fig_caption: true
    df_print: kable
fontsize: 12pt
---

\captionsetup[table]{labelformat=empty}

```{r setup, include=FALSE} 
source("Revised Code.R")

knitr::opts_chunk$set(fig.path='Figs/', fig.align='center',  fig.pos="H", echo=FALSE, warning=FALSE, message=FALSE,  results = 'asis', fig.width = 6.5, fig.height = 4.5, dev = 'pdf')

\ pagebreak

100天内的重新录取摘要

summaryTable(wdata$readm, table.title="Readmissions Within 100 Days", y.labels="Number of Readmissions")

summaryTable(wdata$readm, table.title="Readmissions Within 100 Days", y.labels="Number of Readmissions", freq.tab=T)

summaryTable(wdata$readm.any, table.title="Readmissions Within 100 Days", freq.tab=T, y.name="Readmission", y.labels=c("No Readmission", "Any Readmission"))

\ pagebreak

再入学与捐赠者类型之间的关联

summaryTable(y=wdata$donor, table.title="Donor Type", freq.tab=T, y.name="Donor Type")

summaryTable(y=wdata$donor.3cat, table.title="Association Between Readmissions and Donor Type (3 Groups)", freq.tab=T, y.name="Donor Type", y.labels=c("Matched Sibs", "MUD", "Others"))

regTable.logistic(formula=wdata$readm.any~as.factor(wdata$donor.3cat), response = "Readmission", y.name="Donor Type (3 Groups)", y.labels=c("MUD vs Matched Sibs", "Others vs Matched Sibs"))

summaryTable(y=wdata$readm.any, bygroup=as.numeric(wdata$donor.3cat), freq.tab=T, bygroup.name="Donor Type", y.name="Readmissions", bygroup.labels=c("Matched Sibs", "MUD", "Others"), caption_heading="Note:", caption = "0: No Readmission; 1: Any Readmission")

\ pagebreak

再入院与移植前疾病相关特征之间的关联

HCT-CI

summaryTable(y=wdata$HCTCI.score, table.title="HCT-CI Raw Score", y.labels="Number of Readmissions")

summaryTable(y=wdata$HCTCI.score, table.title="Readmissions", freq.tab=T, y.name="HCT-CI Raw Score")

summaryTable(y=wdata$HCTCI.3cat, table.title="HCT-CI Score (3 Groups)", caption_heading="Note:", caption="1: Score=0; 2: Score=1-2; 3: Score=3+", freq.tab=T, y.labels=c("0", "1-2", "3+"))

\ pagebreak

文档结尾

只有当我尝试将其编织为PDF时,才会出现以下错误:

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
! Illegal unit of measure (pt inserted).
<to be read again> 
                   )
l.1949 \item
             \underline{\textit{Note:}} 

Error: Failed to compile Revised_Code.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See Revised_Code.log for more info.
Execution halted

如何解决该问题?

编辑1

这是Revised_Code.tex:


    \documentclass[12pt,]{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}
        \setmainfont[]{Times New Roman}
    \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[left=.5in,right=.5in,top=1in,bottom=1in]{geometry}
    \usepackage{hyperref}
    \hypersetup{unicode=true,
                pdfauthor={; ; ; ;},
                pdfborder={0 0 0},
                breaklinks=true}
    \urlstyle{same}  % don't use monospace font for urls
    \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}{5}
    % 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
    \providecommand{\subtitle}[1]{
      \posttitle{
        \begin{center}\large#1\end{center}
        }
    }

    \setlength{\droptitle}{-2em}

      \title{\vspace{2in}Analysis for the Study\(\colon\) Readmissions}
        \pretitle{\vspace{\droptitle}\centering\huge}
      \posttitle{\par}
      \subtitle{\vspace{.2in}\emph{15 July, 2019}}
      \author{\emph{PI$\colon$ Name} \\ \emph{Professor} \\ \vspace{.5in}\emph{Name} \\ \emph{Position} \\ \emph{email}}
        \preauthor{\centering\large\emph}
      \postauthor{\par}
          \predate{\centering\large\emph}
      \postdate{\par}
        \date{\vspace{4in}}

    \usepackage{booktabs}
    \usepackage{longtable}
    \usepackage{array}
    \usepackage{multirow}
    \usepackage{wrapfig}
    \usepackage{float}
    \usepackage{colortbl}
    \usepackage{pdflscape}
    \usepackage{tabu}
    \usepackage{threeparttable}
    \usepackage{threeparttablex}
    \usepackage[normalem]{ulem}
    \usepackage{makecell}
    \usepackage{xcolor}

    \usepackage{fancyhdr}
    \usepackage{titling}
    \usepackage{caption}
    \usepackage{booktabs}
    \fancyhead[L]{\includegraphics[width=2cm]{pic.png}}
    \fancyhead[R]{\includegraphics[width=4cm]{pic.png}}
    \fancyfoot[C]{Department}
    \fancypagestyle{plain}{\pagestyle{fancy}}

    \begin{document}
    \maketitle

    {
    \setcounter{tocdepth}{4}
    \tableofcontents
    }
    \captionsetup[table]{labelformat=empty}

    \pagebreak

    \section{Summary of Readmissions within 100
    days}\label{summary-of-readmissions-within-100-days}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-1}Readmissions Within 100 Days}
    \centering
    \begin{tabular}{lcccccc}
    \toprule
      & n & Mean & Std & Min & Median & Max\\
    \midrule
    \rowcolor{gray!6}  y & 147 & 0.537415 & 0.7961561 & 0 & 0 & 4\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-1}Readmissions Within 100 Days}
    \centering
    \begin{tabular}{lcc}
    \toprule
      & Frequency & X.\\
    \midrule
    \rowcolor{gray!6}  0 & 90 & 61.224\\
    1 & 40 & 27.211\\
    \rowcolor{gray!6}  2 & 13 & 8.844\\
    3 & 3 & 2.041\\
    \rowcolor{gray!6}  4 & 1 & 0.680\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-1}Readmissions Within 100 Days}
    \centering
    \begin{tabular}{ccc}
    \toprule
    Readmission & Frequency & \%\\
    \midrule
    \rowcolor{gray!6}  No Readmission & 90 & 61.224\\
    Any Readmission & 57 & 38.776\\
    \bottomrule
    \end{tabular}
    \end{table}

    \pagebreak

    \section{Association Between Readmissions and Donor
    Type}\label{association-between-readmissions-and-donor-type}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-2}Donor Type}
    \centering
    \begin{tabular}{lcc}
    \toprule
      & Frequency & X.\\
    \midrule
    \rowcolor{gray!6}  0 & 46 & 31.081\\
    1 & 64 & 43.243\\
    \rowcolor{gray!6}  2 & 25 & 16.892\\
    3 & 5 & 3.378\\
    \rowcolor{gray!6}  4 & 6 & 4.054\\
    \addlinespace
    5 & 2 & 1.351\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-2}Association Between Readmissions and Donor Type (3 Groups)}
    \centering
    \begin{tabular}{ccc}
    \toprule
    Donor Type & Frequency & \%\\
    \midrule
    \rowcolor{gray!6}  Matched Sibs & 46 & 31.081\\
    MUD & 89 & 60.135\\
    \rowcolor{gray!6}  Others & 13 & 8.784\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]
    \centering
    \begin{tabular}{ccccc}
    \toprule
    Donor Type (3 Groups) & OR & CI Lower & CI Upper & p value\\
    \midrule
    \rowcolor{gray!6}  MUD vs Matched Sibs & 1.360 & 0.649 & 2.850 & 0.415\\
    Others vs Matched Sibs & 0.833 & 0.222 & 3.135 & 0.787\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]
    \centering
    \begin{threeparttable}
    \begin{tabular}{cccccccc}
    \toprule
      & Readmissions & 0 & \% & 1 & \% & Total & \%\\
    \midrule
    \rowcolor{gray!6}  Donor Type &  &  &  &  &  &  & \\
    Matched Sibs &  & 30 & 65.22 & 16 & 34.78 & 46 & 100\\
    \rowcolor{gray!6}  MUD &  & 51 & 57.95 & 37 & 42.05 & 88 & 100\\
    Others &  & 9 & 69.23 & 4 & 30.77 & 13 & 100\\
    \rowcolor{gray!6}  Total &  & 90 & 61.22 & 57 & 38.78 & 147 & 100\\
    \bottomrule
    \end{tabular}
    \begin{tablenotes}[para]
    \item \underline{\textit{Note:}} 
    \item 0: No Readmission; 1: Any Readmission
    \end{tablenotes}
    \end{threeparttable}
    \end{table}

    \pagebreak

    \section{Association Between Readmissions and Pre-Transplant Disease
    Related
    Characteristics}\label{association-between-readmissions-and-pre-transplant-disease-related-characteristics}

    \subsection{HCT-CI}\label{hct-ci}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-3}HCT-CI Raw Score}
    \centering
    \begin{tabular}{lcccccc}
    \toprule
      & n & Mean & Std & Min & Median & Max\\
    \midrule
    \rowcolor{gray!6}  y & 148 & 1.986487 & 1.319588 & 0 & 2 & 7\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-3}Readmissions}
    \centering
    \begin{tabular}{lcc}
    \toprule
      & Frequency & X.\\
    \midrule
    \rowcolor{gray!6}  0 & 19 & 12.838\\
    1 & 37 & 25.000\\
    \rowcolor{gray!6}  2 & 44 & 29.730\\
    3 & 29 & 19.595\\
    \rowcolor{gray!6}  4 & 16 & 10.811\\
    \addlinespace
    5 & 1 & 0.676\\
    \rowcolor{gray!6}  6 & 1 & 0.676\\
    7 & 1 & 0.676\\
    \bottomrule
    \end{tabular}
    \end{table}

    \begin{table}[!h]

    \caption{\label{tab:unnamed-chunk-3}HCT-CI Score (3 Groups)}
    \centering
    \begin{threeparttable}
    \begin{tabular}{lcc}
    \toprule
      & Frequency & X.\\
    \midrule
    \rowcolor{gray!6}  [0,1) & 19 & 12.838\\
    [1,3) & 81 & 54.730\\
    \rowcolor{gray!6}  [3,8) & 48 & 32.432\\
    \bottomrule
    \end{tabular}
    \begin{tablenotes}[para]
    \item \underline{\textit{Note:}} 
    \item 1: Score=0; 2: Score=1-2; 3: Score=3+
    \end{tablenotes}
    \end{threeparttable}
    \end{table}

    \pagebreak


    \end{document}

编辑2

导致错误的表应该看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:1)

“非法计量单位(插入点)。”当为块选项 out.height 输入数值时,也可能出现错误。例如 out.height=200 生成此错误,应将其替换为 out.height="200px"