2

I have this code contained in a .Rnw file:

\documentclass[a4paper,11pt]{article}

\usepackage{lipsum} % Required to insert dummy text

\begin{document}
\title{}
\date{\today}
\maketitle

\section{Header}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

<<model_terms, results = "asis", echo = F>>=
library(stargazer); library(knitr)

df <- data.frame(terms = "predictor1 | predictor2")

stargazer(df, summary = F)

@

\end{document}

If I run library(knitr); knit() on this file, I get this outputted in a PDF:

enter image description here

Note the space before the pipe but not after. How can I insert a space after the pipe. So output should look like this:

predictor1 | predictor2
Thomas
  • 43,637
  • 12
  • 109
  • 140
luciano
  • 13,158
  • 36
  • 90
  • 130

1 Answers1

2

The issue here is in how stargazer sanitizes the LaTeX.

Change:

stargazer(df, summary = F)

To:

cat(gsub('textbar', 'textbar{}', capture.output(stargazer(df, summary = F))), sep='\n')

I would suggest reporting this to the package maintainer as a possible bug. In most cases, I think the \textbar{} representation rather than \textbar is probably what users want.

Thomas
  • 43,637
  • 12
  • 109
  • 140