R Markdown呈现编号列表逐字而不包装

时间:2017-02-13 05:20:46

标签: r pdf text markdown r-markdown

我正在做作业(是的),但这个问题是关于我用来呈现答案的R Markdown,而不是作业问题本身。我希望这很好。

当我在有序列表中使用代码块时(问题已编号,因此几乎所有内容都在编号列表中),然后在逐字渲染后排序列表项(因此内联方程式呈现为:$ \ beta_0 $而不是显示即使我有tidy = TRUE并且width.cutoff设置为50,它们也不会换行。它们会在页面上运行。它们也没有缩进,这使得它们更清楚地表明它们没有被评估为有序列表项。由于某种原因,width.cutoff选项适用于代码块,但不适用于有序列表项。我无法在网上找到此错误。我发现了这些问题: How to wrap code and the output in markdown (.Rmd)

knitr: How to prevent text wrapping in output?

In R markdown in RStudio, how can I prevent the source code from running off a pdf page?

但他们似乎只是告诉我玩宽度或宽度。切断选项,我已经完成并且没有工作。我在下面附上一些测试代码,以及pdf出来的截图(link to disappointing image)。如你所见,a。部分出来很好,但b,c和子问题没有。在较大的文件中,顶级编号列表也存在此问题。如果有人有任何想法,请告诉我。

另外,我不知道这是否重要,但这些线条在RStudio中以蓝色显示,除非我在它们之前添加另一个换行符,在这种情况下它们会变回黑色,然后在蓝色和黑色之间交替。但颜色看起来并不重要,它们仍然在同一个地方以相同的方式呈现。我在前一行的末尾尝试了双倍空格,没有变化。使它们不能逐字渲染的唯一因素是删除它们之前的新行并允许它们位于它们上方的文本行旁边,但由于它们不是缩进的,因此它们看起来像它们一样。是上一个问题的一部分,并且对阅读有问题。提前感谢您的帮助!

---
title: "TestThing"
output:
  pdf_document:
    latex_engine: xelatex
header-includes:
- \usepackage{amsmath,amsthm,amssymb,graphicx,epstopdf}
---
```{r echo=FALSE, warning=FALSE}
library(knitr)
library(foreign)
library(car)
library(xtable)
library(plyr)
library(reshape2)
```
```{r set-options, echo=FALSE, cache=FALSE}
options(width=50)
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = TRUE, size="small", width.cutoff=50)
```


3. Problem 3 
    (a) Some amount of text. 

Solving for $\hat{\beta}$:

\begin{equation}
\begin{aligned}
(y-X\hat{\beta})'(y-X\hat{\beta}) &= y'y - \hat{\beta}'X'y - y'X\hat{\beta} + \hat{\beta}'X'X\hat{\beta} \\
... \\
\hat{\beta} &= (X'X)^{-1}(X'y)
\end{aligned}
\end{equation}

This solution is well-defined if there is no perfect collinearity among variables (that is, __X__ has full rank). 



    (b) Text long enough to show that it runs off the page. Why would it do that? After all the width options I set for it... Show that the conditional expectation function yadda yadda etc. etc.. 

The Zero Conditional Mean Assumption sucks. Since the fitted value $\hat{y}$ is created using OLS estimation and $\hat{y} = X\beta$, E[y|X] = $X\beta$ when the Zero Conditional Mean assumption holds. 


    (c) Express the values in terms of things. 
        a. Express the values in terms of the conditional expectations of X and Y:  

B = E[Y|X=1]  
C = E[Y|X=0]  
D = B-C = unit change in Y per increase of 1 in X  


        b. Express the values in terms of $\beta_0$ and $\beta_1$:

B = $\beta_0 + \beta_1$  
C = $\beta_0$  
D = $\beta_1$   


        c. Use the data to estimate B, C, D, $\beta_0$ and $\beta_1$:   


```{r echo=FALSE, results="asis"}
datathing <- data.frame(X=c(0,0,1,1), Y=c(1,3,5,7))
print(xtable(summary(lm(datathing$Y ~ datathing$X))), comment=FALSE)
```

B = $\beta_0 + \beta_1$ = 2 + 4 = 6  
C = $\beta_0$ = 2  
D = $\beta_1$ = 4  

0 个答案:

没有答案