R Markdown 是基于 Pandoc Markdown,是 Pandoc 转化器对 Markdown 的支持,这种支持包括 Markdown 文本里插入 LaTeX 代码,至少认真把网页 https://pandoc.org/MANUAL.html#pandocs-markdown 看一遍,你就会明白了
如果需要在 R 代码块执行后,对图有特殊的排版要求,有种做法就是对生成的 LaTeX 文本进行替换、插入一些 LaTeX 命令,举个例子 https://github.com/rstudio/rmarkdown-book/blob/master/index.Rmd#L30-L53 代码块控制表格16.1 的输出样式 https://github.com/rstudio/rmarkdown-book/blob/master/16-widgets.Rmd#L374-L394
这是个比较高级的魔法,需要会一点正则表达式,谢大的这个例子,没有启用 raw strings 匹配,导致转义符 \
超多,你得慢慢理解
最后就你这个具体的问题,谢大的 knitr 包已经提供超多的图形格式控制,见 https://yihui.name/knitr/options/#plots 其中,fig.cap="中文题目"
即可
附:
表格转化前
\begin{longtable}[]{@{}ll@{}}
\caption{\label{tab:sizing-policy} Options that can be specified within a sizing policy.}\tabularnewline
\toprule
\begin{minipage}[b]{0.47\columnwidth}\raggedright
Option\strut
\end{minipage} & \begin{minipage}[b]{0.47\columnwidth}\raggedright
Description\strut
\end{minipage}\tabularnewline
\midrule
\endfirsthead
\toprule
\begin{minipage}[b]{0.47\columnwidth}\raggedright
Option\strut
\end{minipage} & \begin{minipage}[b]{0.47\columnwidth}\raggedright
Description\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Default widget width in all contexts (browser, viewer, and knitr).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Similar to \texttt{defaultWidth}, but for heights instead.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{padding}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
The padding (in pixels) in all contexts.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{viewer.defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Default widget width within the RStudio Viewer.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{viewer.defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Similar to \texttt{viewer.defaultWidth}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{viewer.padding}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Padding around the widget in the RStudio Viewer (defaults to 15 pixels).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{viewer.fill}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
When displayed in the RStudio Viewer, automatically size the widget to the viewer dimensions. Default to \texttt{TRUE}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{viewer.suppress}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Never display the widget within the RStudio Viewer (useful for widgets that require a large amount of space for rendering). Defaults to \texttt{FALSE}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{viewer.paneHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Request that the RStudio Viewer be forced to a specific height when displaying this widget.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{browser.defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Default widget width within a standalone web browser.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{browser.defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Similar to \texttt{browser.defaultWidth}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{browser.padding}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Padding in a standalone browser (defaults to 40 pixels).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{browser.fill}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
When displayed in a standalone web browser, automatically size the widget to the browser dimensions. Defaults to \texttt{FALSE}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{browser.external}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Always use an external browser (via \texttt{browseURL()}). Defaults to \texttt{FALSE}, which will result in the use of an internal browser within RStudio v1.1 and higher.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{knitr.defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Default widget width within documents generated by \textbf{knitr} (e.g., R Markdown).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{knitr.defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Similar to \texttt{knitr.defaultWidth}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.47\columnwidth}\raggedright
\textbf{knitr.figure}\strut
\end{minipage} & \begin{minipage}[t]{0.47\columnwidth}\raggedright
Apply the default \textbf{knitr} \texttt{fig.width} and \texttt{fig.height} to the widget rendered in R Markdown. Defaults to \texttt{TRUE}.\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}
表格转化后
\begin{table}
\caption{\label{tab:sizing-policy} Options that can be specified within a sizing policy.}\tabularnewline
\begin{tabular}{ll}
\toprule
\begin{minipage}[b]{0.33\columnwidth}\raggedright
Option\strut
\end{minipage} & \begin{minipage}[b]{0.65\columnwidth}\raggedright
Description\strut
\end{minipage}\tabularnewline
\midrule
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Default widget width in all contexts (browser, viewer, and knitr).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Similar to \texttt{defaultWidth}, but for heights instead.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{padding}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
The padding (in pixels) in all contexts.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{viewer.defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Default widget width within the RStudio Viewer.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{viewer.defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Similar to \texttt{viewer.defaultWidth}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{viewer.padding}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Padding around the widget in the RStudio Viewer (defaults to 15 pixels).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{viewer.fill}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
When displayed in the RStudio Viewer, automatically size the widget to the viewer dimensions. Default to \texttt{TRUE}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{viewer.suppress}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Never display the widget within the RStudio Viewer (useful for widgets that require a large amount of space for rendering). Defaults to \texttt{FALSE}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{viewer.paneHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Request that the RStudio Viewer be forced to a specific height when displaying this widget.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{browser.defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Default widget width within a standalone web browser.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{browser.defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Similar to \texttt{browser.defaultWidth}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{browser.padding}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Padding in a standalone browser (defaults to 40 pixels).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{browser.fill}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
When displayed in a standalone web browser, automatically size the widget to the browser dimensions. Defaults to \texttt{FALSE}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{browser.external}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Always use an external browser (via \texttt{browseURL()}). Defaults to \texttt{FALSE}, which will result in the use of an internal browser within RStudio v1.1 and higher.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{knitr.defaultWidth}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Default widget width within documents generated by \textbf{knitr} (e.g., R Markdown).\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{knitr.defaultHeight}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Similar to \texttt{knitr.defaultWidth}.\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.33\columnwidth}\raggedright
\textbf{knitr.figure}\strut
\end{minipage} & \begin{minipage}[t]{0.65\columnwidth}\raggedright
Apply the default \textbf{knitr} \texttt{fig.width} and \texttt{fig.height} to the widget rendered in R Markdown. Defaults to \texttt{TRUE}.\strut
\end{minipage}\tabularnewline
\bottomrule
\end{tabular}
\end{table}
就其中一段判断是否有 Table 16.1 的正则 0.47\\\\columnwidth
来说,在 https://regex101.com/ 中输入
以后不管是什么环境(图,表),都可以照这个路子,仿写谢大这段代码