knitr 出力チャンクを変更する方法

knitr 出力チャンクを変更する方法

knitrコード チャンクの出力を微調整して、希望どおりの外観にすることは可能です。問題はparskipパッケージの使用時に発生します。parskipパッケージにより、コード出力の下に余分なスペースが追加され、見栄えが悪くなります。最小限の.Rnwファイルを以下に示します。

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{parskip}

\begin{document}
\setlength{\parindent}{0in}
Some text above chunk
<<echo=TRUE>>=
2 + 2
@
Some text below. The space above this is too big when using the \texttt{parskip} package.
Some text below. The space above this is too big when using the \texttt{parskip} package.
Some text below. The space above this is too big when using the \texttt{parskip} package.

A nice space between paragraphs.
\end{document}

答え1

これはエレガントな答えではありませんが、負の垂直スペースを含めることで余分なスペースを「修正」できます。変更されたコードを参照してください。

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
%\usepackage{parskip}

\begin{document}
\setlength{\parindent}{0in}
Some text above chunk
<<echo=TRUE>>=
2 + 2
@
\vspace{-1em}  %%% this moves the following text up the height of an 'm'
Some text below. The space above this is too big when using the \texttt{parskip} package.
Some text below. The space above this is too big when using the \texttt{parskip} package.
Some text below. The space above this is too big when using the \texttt{parskip} package.

A nice space between paragraphs.
\end{document}

関連情報