Rmarkdown罗马数字嵌套列表失效问题及解决咨询
问题:RMarkdown罗马数字外层嵌套列表失效问题
需求与问题
想要在RMarkdown中创建外层罗马数字、内层阿拉伯数字的嵌套列表,预期格式如下:
I. The first item 1. The first subitem II. The second item 1. The second subitem
实际操作时,第一个嵌套子列表显示正常,但第二个嵌套子列表无法被识别;而外层为阿拉伯数字的嵌套列表可正常渲染。
最小示例
--- title: Minimal Example output: html_document --- The first list (works fine): I. The first item II. The second item Second list: I. The first item 1. The first subitem II. The second item 1. The second subitem For comparison, a third list, only with Arabic numbers (works fine): 1. The first item 1. The first subitem 2. The second item 1. The second subitem
输出情况
第一、第三个列表格式正常;第二个列表中第一个子项格式正常,但第二个子项未被识别为列表,直接以普通文本显示。
原因分析
这是RMarkdown底层的Pandoc解析规则导致的:当外层用.后缀的罗马数字时,Pandoc会把II.误认为是第一个列表项的续行,而非新的列表项,后续的子列表因此无法关联到新的外层项上。而阿拉伯数字列表的序号是连续递增的,不会触发这个解析歧义。
解决办法
方法1:改用括号式罗马数字标记外层列表
将外层的I.、II.替换为(I)、(II),Pandoc能正确识别为独立列表项,嵌套子列表即可正常渲染:
--- title: Fixed Example output: html_document --- Fixed list with parenthesized Roman numerals: (I) The first item 1. The first subitem (II) The second item 1. The second subitem
方法2:使用HTML标签强制定义格式
如果必须保留.后缀的罗马数字格式,可直接用HTML标签手动定义列表结构,完全控制渲染效果:
--- title: Fixed Example output: html_document --- Fixed list with HTML tags: <ol type="I"> <li>The first item <ol type="1"> <li>The first subitem</li> </ol> </li> <li>The second item <ol type="1"> <li>The second subitem</li> </ol> </li> </ol>
内容的提问来源于stack exchange,提问作者Lucas De Abreu Maia
相关产品推荐
相关产品推荐

