如何修改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}

相關內容