Latex R markdown:如何创建一个包含图像和文本的表格,这些图像和文本应以PDF格式编制?
我想在使用R标记编译的PDF报告中包含一个包含两列的表,包括图像和文本(图像描述)。 在此过程中,我对我的表格有以下要求:Latex R markdown:如何创建一个包含图像和文本的表格,这些图像和文本应以PDF格式编制?,latex,markdown,r-markdown,kable,kableextra,Latex,Markdown,R Markdown,Kable,Kableextra,我想在使用R标记编译的PDF报告中包含一个包含两列的表,包括图像和文本(图像描述)。 在此过程中,我对我的表格有以下要求: 宽度:固定列宽或表宽 对齐:列中的内容对齐 第1列中图像的上止点对齐 第2列中文本的左上对齐方式 文本内容:最好是简单易读的代码 文本格式: 需要文本格式,最多使用标记语法,即,bold 需要换行符 图像路径:由于图像存储在子目录中,因此最好使用缩写图像路径,如 figpath针对您的latex方法: 垂直对齐:第2列的工作不正常 通过组合p列(而不是使用的m
- 宽度:固定列宽或表宽
- 对齐:列中的内容对齐
- 第1列中图像的上止点对齐
- 第2列中文本的左上对齐方式
- 文本内容:最好是简单易读的代码
- 文本格式:
- 需要文本格式,最多使用标记语法,即,bold
- 需要换行符
- 图像路径:由于图像存储在子目录中,因此最好使用缩写图像路径,如
figpath针对您的latex方法:
- 垂直对齐:第2列的工作不正常
通过组合p列(而不是使用的m列)和顶部对齐的图像,可以获得所需的对齐方式。对于顶部对齐的图像,将
添加到标题中,并在图像选项中添加\usepack[export]{adjustbox}
,valign=t
- 图像路径:不能包含缩写图像路径
使用头文件中的
可以很容易地使用图像路径\graphicspath{{{./older/Subfolder/}}
- 使用
作为浮点说明符通常不是一个好主意。这基本上保证了次优的图像放置。相反,请使用[H]
确保latex为您的图像找到最佳位置[htbp]
- 不要在表中使用
,这就是\toprule
的用途\midrule
- 加载
包时,不要使用图书标签
,因为该包提供了具有更大间距的备选方案\hline
感谢您的LaTex reprex:图形路径、标题和引用现在可以正常工作了!正如在中一样,我试着引用As
。在一个简单的降价文档中,添加\cite{R-base}
是有效的,但随后以PDF格式显示[?]。用pdflatex编译\书目{references.bib}
ed.tex文件并不能解决这个问题。另外,另外添加keep_tex
会导致错误:\书目样式{apa}
。您有什么建议吗?新的列对齐方式在一个简单的标记文件中工作得很好,但在一个包含以下内容的报告中不行:!未定义的控制序列\protect\astroncite{{R CoreTeam}{2018}
产生错误“tlmgr search--file--global'/biblatex dm.cfg'!Package xkeyval error:,valign=t
Gin.”并添加valign'undefined in families
生成错误“tlmgr search--file--global'/biblatex dm.cfg'!包数组错误:使用了非法的pream令牌(L):'c'。有什么解决方法吗?@mavericks您能共享一个复制您的问题的.tex文件吗?(我不是一个喜欢降价的人,但我可以从tex的角度来看问题)问题似乎在于降价/减记和LaTex之间的相互作用,所以LaTex在这里似乎没有太大问题。即使对于像\begin{tablar}{6cm}L{8.5cm}}
bookdown这样简单的表格环境,也会产生以下错误:!LaTeX错误:数组arg中的字符非法。有关说明,请参阅LaTeX手册或LaTeX配套手册。键入H以获得即时帮助。。。l、 201\begin{tabular}{{}c m{9cm}{}}@mavericks您是否可以共享.tex文件以找出问题的根源?请参阅以获取更精确/详细的版本。非常感谢您的建议!\begin{tablar}{{}c m{9cm}{}
YAML header: header-includes: \usepackage{array} \newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}} \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}} \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}} \begin{table}[H] \centering \caption{My caption} \begin{tabular}{@{} C{6cm} L{9cm} @{}} \\ \toprule Image & Description \\ \toprule \includegraphics[width=60mm]{Folder/Subfolder/image1.png} & \textbf{Lorem ipsum dolor sit amet} [@R-base] \linebreak mauris mauris sollicitudin malesuada amet.\\ & \\ \hline & \\ \includegraphics[width=60mm]{Folder/Subfolder/image2.png} & \textbf{Lorem ipsum dolor} [@R-bookdown]\linebreak sit amet, mauris mauris sollicitudin malesuada amet. \ \end{tabular} \end{table}
Table: Caption of my table <!-- Table: (\#tab:myTable-reference) Caption of my table --> | Image | Description | | :-------: | :----------- | | ![](Folder/Subfolder/image1.png){#id .class height=50%} | **Image description** [@R-base] <br/>Lorem ipsum dolor sit amet, ... | | ![](Folder/Subfolder/image2.png){#id .class height=50%} | **Image description** [@R-bookdown] <br/>Lorem ipsum dolor sit amet, ... | | | |
Refer to this table with [foo] or \@ref(tab:foo) or \@ref(fig:foo). (ref:foo-caption) caption (ref:foo-scaption) short caption ```{r foo, echo=FALSE, out.width='90%', fig.align = "center", fig.cap='(ref:foo-caption)', fig.scap='(ref:foo-scaption)', results='asis'} library(stringi) some_text <- stri_rand_lipsum(1) some_text <- paste("**Image description**", "[@R-bookdown]", "<br/>", some_text) figpath <- "Folder/Subfolder/" dat <- data.frame( Image = c( paste0("![](", figpath, "image1.png){#id .class height=120px}"), paste0("![](", figpath, "image2.png){#id .class height=120px}") ), Description = c( some_text, # TEXT IMAGE 1 some_text # TEXT IMAGE 2 ) ) library(knitr) kable(dat, format = 'pandoc') ```
Refer to this table with [foo2] or \@ref(tab:foo2) or \@ref(fig:foo2). (ref:foo2-caption) caption (ref:foo2-scaption) short caption ```{r foo2, echo=FALSE, out.width='90%', fig.align = "center", fig.cap='(ref:foo2-caption)', fig.scap='(ref:foo2-scaption)', results='asis'} library(kableExtra) kable(dat) %>% kable_styling(full_width = F) %>% column_spec(1, width = "30em") ```
\documentclass{article} \usepackage{booktabs} \usepackage{graphicx} \usepackage{array} \usepackage[export]{adjustbox} \newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} \graphicspath{{./older/Subfolder/}} \begin{document} \begin{table}[htbp] \centering \caption{My caption} \label{foo} \begin{tabular}{@{} L{6cm} L{8.5cm} @{}} \toprule Image & Description \\ \midrule \includegraphics[width=60mm,valign=t]{example-image-duck} & \textbf{Lorem ipsum dolor sit amet} [@R-base] \linebreak mauris mauris sollicitudin malesuada amet.\\ \midrule \includegraphics[width=60mm,valign=t]{example-image-duck} & \textbf{Lorem ipsum dolor} [@R-bookdown]\linebreak sit amet, mauris mauris sollicitudin malesuada amet. \\ \bottomrule \end{tabular} \end{table} \ref{foo} \end{document}
- 垂直对齐:第2列的工作不正常
通过组合p列(而不是使用的m列)和顶部对齐的图像,可以获得所需的对齐方式。对于顶部对齐的图像,将