简体   繁体   English

使用 R,RStudio Knit 转 PDF,如何传递波浪号以防止换行“Table~\\ref{table:data-from-phone}”?

[英]Using R, RStudio Knit to PDF, how to pass tilde to prevent line wrapping "Table~\ref{table:data-from-phone}"?

In Latex, it is common to reference a label using the "~" to keep the number attached to the label such as Figure or Table.在 Latex 中,通常使用“~”来引用标签以将数字附加到标签上,例如 Figure 或 Table。

https://tex.stackexchange.com/questions/227285/problems-with-tilde-and-line-breaking/227296 shows an example of this. https://tex.stackexchange.com/questions/227285/problems-with-tilde-and-line-break/227296展示了一个例子。

A fully working example can be found here:一个完整的示例可以在这里找到:

http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/ http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/

In the Rmd file, http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.Rmd ,在 Rmd 文件中, http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.Rmd

I have the following:我有以下几点:

---
title: "Untitled"
output:
  pdf_document:
    keep_tex: true
    number_sections: true
    latex_engine: pdflatex
---


\section{My Section Name}
\label{sec:my}

Below you will find Equation~\ref{eq:my-model}.

\begin{equation}
\label{eq:my-model}
    Y_{jt} = \alpha + \beta X_{jt} + \upsilon_{j}  + \varepsilon_{jt} ,
\end{equation}


\subsection{My sub section}
\label{sec:mysub}

For more information, please refer to Section~\ref{sec:my}.

Notice the "~" tilde being used as outlined in basic Latex usage.请注意“~”波浪号的使用,如基本 Latex 用法中所述。

When I click Knit-PDF, it outputs something I did not expect:当我点击 Knit-PDF 时,它输出了一些我没想到的东西:

http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.pdf http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.pdf

Since I choose "keep_tex", I can view the .TEX file由于我选择了“keep_tex”,所以可以查看.TEX文件

http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.tex which can be seen online here: http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.tex.txt http://md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.tex可以在这里在线查看: http : //md5.mshaffer.com/WSU_STATS419/stackoverflow/tilde/reference-tilde.tex。文本

It appears to have replaced the tilde with a text version:它似乎已经用文本版本替换了波浪号:

\begin{document}
\maketitle

\section{My Section Name}
\label{sec:my}

Below you will find Equation\textasciitilde{}\ref{eq:my-model}.

\begin{equation}
\label{eq:my-model}
    Y_{jt} = \alpha + \beta X_{jt} + \upsilon_{j}  + \varepsilon_{jt} ,
\end{equation}

\subsection{My sub section}
\label{sec:mysub}

For more information, please refer to
Section\textasciitilde{}\ref{sec:my}.

\end{document}

How do I rectify this situation?我该如何纠正这种情况?

How do I get the Latex to render as expected?如何让 Latex 按预期呈现?

How do I get my tilde as a spacer back?如何让我的波浪号作为间隔符回来?

A unicode non-breaking space should work. Unicode 不间断空间应该可以工作。 Or pandoc parses even an HTML entity inside markdown into the correct thing, see eg或者 pandoc 甚至将 markdown 中的 HTML 实体解析为正确的内容,例如

echo ' foo' | pandoc -t latex

~foo

If you must include some hard to parse LaTeX in your markdown, you can use generic raw attributes like:如果您必须在 Markdown 中包含一些难以解析的 LaTeX,您可以使用通用的原始属性,例如:

```{=latex}
my LaTeX
```
  1. According to this question and answer , you can try replacing your tilde with "\\~" or "\\sim" and see which one works.根据this question and answer ,您可以尝试用“\\~”或“\\sim”替换波浪号,看看哪个有效。

  2. Since you kept the .tex file, you can always search+replace the \\textasciitilde{} with a real tilde, even if #1 does not work.由于您保留了 .tex 文件,因此即使 #1 不起作用,您也可以始终使用真正的波浪号搜索+替换\\textasciitilde{}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM