首页 > 解决方案 > 在图的顶部编织标题

问题描述

我想在图形上方显示标题。我四处寻找一些解决方案,但我仍然无法实现我的目标。这是我的代码:

\documentclass{article}
\usepackage{caption}

\begin{document}

<<fig1, echo = F, fig.width=7, fig.height=5, fig.cap= "This is a caption">>=
x = 1:50
y = x^2
plot(x, y)
@

\end{document}

标签: rknitrsweave

解决方案


您需要使用 LaTeX 方法添加标题,knitr不会自动添加。例如,

\documentclass{article}
\usepackage{caption}

\begin{document}

\begin{figure}
\caption{This is a caption}
<<fig1, echo = F, fig.width=7, fig.height=5>>=
x = 1:50
y = x^2
plot(x, y)
@
\end{figure}

\end{document}

如果您跳过该fig.cap选项,您只会插入图形,而不是作为 LaTeX 浮动图形,但您仍然可以将其放入您自己的浮动中。\label如果您想引用该图,您可能需要添加显式,因为knitr在这种简单模式下不会为您添加。


推荐阅读