Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多行表格 6.1 的正确使用姿势 #46

Closed
XiangyunHuang opened this issue Aug 31, 2019 · 5 comments
Closed

多行表格 6.1 的正确使用姿势 #46

XiangyunHuang opened this issue Aug 31, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@XiangyunHuang
Copy link
Owner

根据 Pandoc 官方手册 https://pandoc.org/MANUAL.html#tables 这个多行表格我从原稿的 tex 文件,经

pandoc table.tex -o table.md

转化为

Table: (\#tab:plot-summary) 各种类型的数据对应的统计图形概览

---------- --------------- ---------------- ------------------------ --------
                一维             二维                 高维             矩阵
 分类数据      条形图          马赛克图             马赛克图                  
                            关联图、四瓣图                           
 连续数据      直方图           散点图             平行坐标图         颜色图
               箱线图                        散点图矩阵、三维散点图    热图
            Cleveland 点图                    三维透视图、平滑散点图   等高图
             一维散点图                      星状图、符号图、脸谱图  
 混合数据                     条件密度图           条件分割图        
                                棘状图                               
---------- --------------- ---------------- ------------------------ --------

转化后的md表格插入书籍正文后,在本地和 Travis 编译时,都会伴随一个警告

table

说是我们重复给这个表格打标签,去掉最后一行,警告消失,但是 HTML 格式和 PDF 格式表格都乱了

---------- --------------- ---------------- ------------------------ --------

我不清楚是哪里出问题了,因为我没在其它地方找到 tab:plot-summary 这个标签,并且我将此 md 表格插入到 bookdown-chinese 模板 中一切正常。求助 @yihui @pzhaonet

测试环境: Pandoc 版本 2.7.3

@yihui
Copy link
Collaborator

yihui commented Aug 31, 2019

这个得保留 .tex 文件、从那里面看看究竟怎么 tab:plot-summary 出现多次了。

@XiangyunHuang
Copy link
Owner Author

XiangyunHuang commented Aug 31, 2019

很奇怪这一点我之前也排查过,忘记说了,这是生成的 tex 表格

下面我们对每种数据类型在不同维度下的图形类型做一个简单概括如表 \ref{tab:plot-summary},注意该表格并非一个完整的作图指引,面对实际数据时,我们仍然需要具体问题具体分析。

\begin{longtable}[]{@{}lcccc@{}}
\caption{\label{tab:plot-summary} 各种类型的数据对应的统计图形概览}\tabularnewline
\toprule
\endhead
& 一维 & 二维 & 高维 & 矩阵\tabularnewline
分类数据 & 条形图 & 马赛克图 & 马赛克图 &\tabularnewline
& & 关联图、四瓣图 & &\tabularnewline
连续数据 & 直方图 & 散点图 & 平行坐标图 & 颜色图\tabularnewline
& 箱线图 & & 散点图矩阵、三维散点图 & 热图\tabularnewline
& Cleveland 点图 & & 三维透视图、平滑散点图 & 等高图\tabularnewline
& 一维散点图 & & 星状图、符号图、脸谱图 &\tabularnewline
混合数据 & & 条件密度图 & 条件分割图 &\tabularnewline
& & 棘状图 & &\tabularnewline
\bottomrule
\end{longtable}

附件是生成的 tex 文件,因为不能上传 TeX 格式文件,我把它打包成 zip 格式了

_main.zip
_main.pdf

@XiangyunHuang XiangyunHuang added the bug Something isn't working label Aug 31, 2019
@XiangyunHuang
Copy link
Owner Author

XiangyunHuang commented Sep 1, 2019

我搞清楚问题所在了,表格跨页就会导致这个问题,我将上述表格插入的文档中间,这会导致这个表格最终在编译的 PDF 里拆分为两段,所以就报警告了 。

01-introduction.Rmd 文件内容如下

\mainmatter

# 牛刀小试 {#intro}

现在我们可以试试 **bookdown** 的一些初级功能了,例如图表。图 \@ref(fig:hello) 是一幅无趣的散点图,表 \@ref(tab:iris) 是一份枯燥的数据。

```{r hello, fig.cap='雷猴啊,散点图!', out.width='90%'}
par(mar = c(4, 4, 1, .1))
plot(cars, pch = 19)
```

Table: (\#tab:plot-summary) 各种类型的数据对应的统计图形概览

---------- --------------- ---------------- ------------------------ --------
                一维             二维                 高维             矩阵
 分类数据      条形图          马赛克图             马赛克图                  
                            关联图、四瓣图                           
 连续数据      直方图           散点图             平行坐标图         颜色图
               箱线图                        散点图矩阵、三维散点图    热图
            Cleveland 点图                    三维透视图、平滑散点图   等高图
             一维散点图                      星状图、符号图、脸谱图  
 混合数据                     条件密度图           条件分割图        
                                棘状图                               
---------- --------------- ---------------- ------------------------ --------

```{r iris}
knitr::kable(
  head(iris), caption = '雷猴啊,iris 数据!',
  booktabs = TRUE
)
```

就这样,你可以一直编下去,直到编不下去。

生成的 PDF 见 bookdown.pdf

表格分页就分页,应该不妨碍的呀

table

@yihui
Copy link
Collaborator

yihui commented Sep 3, 2019

\label{} 定义在 \caption{} 之内,所以重复标题的时候把这个标签也重复了。

我觉得不是什么重要的问题,就忽略这个警告信息吧。

@XiangyunHuang
Copy link
Owner Author

嗯嗯,好的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants