从 markdown 转换为 PDF 时出现错误消息,包计算错误:`\let' 此时无效

从 markdown 转换为 PDF 时出现错误消息,包计算错误:`\let' 此时无效

我正在尝试将 R markdown 文档转换为 PDF。但是,编译失败并显示以下错误消息: ! Package calc 错误:`\let ' 此时无效。

我的文档由许多子文档组成,我可以单独编译所有子文档而不会发生错误。我没有在 YAML 标头中加载 calc 包,无法弄清楚错误来自哪里。

我是 latex 和 R markdown 的新手,非常感谢任何关于如何解决这个问题的提示!

这是我的 R markdown 代码:

---
output:
  pdf_document:
    fig_caption: yes
    number_sections: yes
bibliography: library.bib
csl: chicago-author-date.csl
urlcolor: black
linkcolor: black
fontsize: 12pt
geometry: margin = 1.2in
header-includes:
- \usepackage{placeins}
- \usepackage{fancyhdr}
- \usepackage{setspace}
- \usepackage{chngcntr}
- \usepackage{microtype}
- \usepackage{mathtools}
- \usepackage{amsmath,amssymb,bm}
- \usepackage{dsfont}
- \usepackage{pdflscape}
- \usepackage{booktabs}
- \usepackage{caption}
- \usepackage{subfig}
- \onehalfspacing
- \counterwithin{figure}{section}
- \counterwithin{table}{section}
---

---
nocite: | 
  @Beck2001, @Piketty2014, @Nickell2006, @LaPorta1997, @Quinn2008
...


```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/',
                  echo = FALSE, warning = FALSE, message = FALSE)
```

\pagenumbering{gobble}

```{r child = 'B.2-title_page.Rmd'}
```

\newpage

```{r child = 'B.3-declaration.Rmd'}
```

\newpage
\pagestyle{fancy}

\fancyhead[LE,RO]{}
\fancyhead[LO,RE]{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}

\pagenumbering{roman}

\fancyhead[CO,CE]{Abstract}
\section*{Abstract}
\addcontentsline{toc}{section}{Abstract}

```{r child = 'B.4-abstract.Rmd'}
```

\newpage
\fancyhead[CO,CE]{Table of Contents}
\setcounter{tocdepth}{2}
\tableofcontents

\newpage
\pagenumbering{arabic}

\newpage
\fancyhead[CO,CE]{Introduction}

```{r child = 'B.5-introduction.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Financial Deregulation and the 'Big Bangs'}

```{r child = 'B.6-big_bang.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Methodology and Data}

```{r child = 'B.7-methodology.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Main Results}

```{r child = 'B.8-main_results.Rmd'}
```

\FloatBarrier
\newpage
\fancyhead[CO,CE]{Conclusion}

```{r child = 'B.9-conclusion.Rmd'}
```

\FloatBarrier

\newpage
\fancyhead[CO,CE]{List of Figures}
\addcontentsline{toc}{section}{List of Figures}
\listoffigures

\newpage
\fancyhead[CO,CE]{List of Tables}
\addcontentsline{toc}{section}{List of Tables}
\listoftables

\newpage
\fancyhead[CO,CE]{Appendix}

```{r child = 'B.10-appendix.Rmd'}
```


\FloatBarrier
\newpage
\fancyhead[CO,CE]{References}

# References

更新 因此,这是我的 markdown 文档的 .tex 版本,无法转换为 PDF。渲染文档 Example.Rmd 本身可以正常工作。但作为子文档包含时会产生上述错误。由于我是 markdown 和 Latex 的绝对初学者,也许我不应该使用\onehalfspacing我以前的方式?

\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,
            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}{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{}
  \pretitle{\vspace{\droptitle}}
  \posttitle{}
  \author{}
  \preauthor{}\postauthor{}
  \date{}
  \predate{}\postdate{}

\usepackage{setspace}
\usepackage{mathtools}

\begin{document}

\noindent\parbox[t]{0.6\textwidth\large}{\raggedright Hello world \\ Hello world \\ Hello world}\hfill
\parbox[t]{0.3\textwidth\large\onehalfspacing}{\raggedright Hello world \\ Hello world}


\end{document}

答案1

你的 es 中的语法\parbox是错误的

\noindent\parbox[t]{0.6\textwidth\large}{\raggedright Hello world \\ Hello world \\ Hello world}\hfill
\parbox[t]{0.3\textwidth\large\onehalfspacing}{\raggedright Hello world \\ Hello world}

应该可能是

\noindent\parbox[t]{0.6\textwidth}{\large\raggedright Hello world \\ Hello world \\ Hello world}\hfill
\parbox[t]{0.3\textwidth}{\large\onehalfspacing\raggedright Hello world \\ Hello world}

的第一个强制参数\parbox必须是长度,并且0.6\textwidth\large不是长度,因为它包含字体大小开关\large。Likewise0.3\textwidth\large\onehalfspacing不是长度,因为它包含\large\onehalfspacing

请注意,只有在加载包时,语法错误才会导致错误calc。否则,TeX 不会抱怨输入错误,而只是在排版框之前执行命令。

相关内容