3

Here is a minimal example:

\documentclass{article}

\begin{document}
<<fig.height=4,out.width=\textwidth,echo=FALSE>>=
plot(1,1)
plot(2,2)
@ 

\newpage
<<fig.height=4,out.width=\textwidth,echo=TRUE>>=
plot(1,1)
plot(2,2)
@ 

\end{document}

Note the screenshots below. If echo=FALSE, horizontal alignment is off. The top plot is shifted to the right relative to the bottom plot. If echo=TRUE, horizontal alignment is correct

horizontal alignment is wrong

horizontal alignment is correct

How would I fix the first example to align correctly with echo=FALSE?

Thank you!

Quinten
  • 35,235
  • 5
  • 20
  • 53
Sang
  • 535
  • 5
  • 14
  • sounds like a bug of a line feed somewhere; I will see. Next time you can report to https://github.com/yihui/knitr/issues thanks! – Yihui Xie Feb 28 '12 at 05:33
  • 3
    I just checked it, and this is expected. Because the default value for the option `fig.align` is `'default'`, which means knitr will not do anything about the plots, and in the tex output you will see code like this: `\includegraphics[width=\textwidth]{figure/chunk1} \includegraphics[width=\textwidth]{figure/chunk2}`, which caused the strange alignment in your case. This can be solved by setting the chunk option `fig.align='center'`. See http://yihui.name/knitr/options – Yihui Xie Feb 28 '12 at 06:21

0 Answers0