在 R Markdown for PDF 中渲染双精度/浮点问题

问题描述 投票:0回答:1

我在 R Markdown 中总结了一列,现在我想将总和插入到表格末尾。

总结代码:

sum_value<-sum(table$Col3)

我尝试使用 dplyr 添加一行来插入总和,但失败了。 现在我只是把总和放在表格的底部。

它应该看起来像:

Col1|Col2|Col3
A|B|111.10
A|C|2353.45
B|D|2364.53

第3列总和:4829.08

Col3 是货币。

插入值代码:

``{=tex}
\centering Sum of Col3: {`r as.double(sum_value)`}
``

但看起来像:4.82908 x10^3

当我在 PDF 文档中使用该值时,我尝试使用

as.integer/double/character(sum_value)
将 Col3 的值转换为双精度、整数和字符,但这不起作用。整数(当然)截取小数,双精度和字符得到 x10^n 输出。

将总和乘以 100 也不起作用。

感谢您的推荐。

编辑。

tex.-文件:

% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}
\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\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}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage[utf8]{inputenc} \usepackage{longtable}
\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}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if
available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\author{}
\date{\vspace{-2.5em}}
\begin{document}
\textbf{H1}
\hfill \includegraphics[width=2.13542in,height=0.57292in]{PATH}
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
\hypertarget{section}{%
\section{}\label{section}}
\hypertarget{section-1}{%
\section{}\label{section-1}}
\hypertarget{section-2}{%
\section{}\label{section-2}}
\centering\LARGE{H2}
\centering\LARGE{H2}
\centering\LARGE{Date1/Date2}
\centering\large(Date3)
\newpage
\listoftables
\newpage
\newpage
\begin{longtable}[]{@{}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1497}}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3653}}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.4072}}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * 
real{0.0778}}@{}}
\caption{Recht}\tabularnewline
\toprule()
\begin{minipage}[b]{\linewidth}\centering
Sale Date
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Author
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Booktitle
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Price
\end{minipage} \\
\midrule()
\endfirsthead
\toprule()
\begin{minipage}[b]{\linewidth}\centering
Sale Date
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Author
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Booktitle
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
Price
\end{minipage} \\
\midrule()
\endhead
13.09.2000 & NN, VN & Title1 & 189.1 \\
15.12.2000 & NN, VN & Title2 & 23.66 \\
18.03.2000 & NN, VN & Title3
Title & 19 \\
15.02.2000 & NN, VN & Title4
& 76.94 \\
14.02.2000 & NN, VN & Title5
Title & 90.38 \\
15.02.2000 & NN, VN & Title6 & 56.43 \\
15.02.2000 & NN, VN & Title7 &
16.41 \\
15.02.2000 & NN, VN & Title8 &
236.2 \\
09.05.2000 & NN, VN & Title9
& 40.92 \\

\bottomrule()
\end{longtable}
\centering Sum of Col4: {\ensuremath{12.12343534\times 10^{6}}}
\newpage
\end{document}
pdf r-markdown double rendering
1个回答
0
投票

好吧,我的问题提出一年后,我自己得到了它。 我添加了以下代码:

```{r echo=FALSE}
options("scipen"=100, "digits"=6)
```

因此整个文档中的科学记数法都消失了。

© www.soinside.com 2019 - 2024. All rights reserved.