You need to enable JavaScript to run this app. 如何在tufte风格Bookdown HTML输出中按章节重置旁注编号
优惠活动
大模型
产品
解决方案
定价
更多

如何在tufte风格Bookdown HTML输出中按章节重置旁注编号

首先替换你现有自定义CSS为以下内容即可实现每章重置旁注编号:

/* 隐藏默认生成的旁注编号,避免重复显示 */
.sidenote-number sup {
  display: none;
}
.sidenote li::marker {
  content: none;
}

/* 每章开头重置两个旁注计数器:分别对应正文标记、旁注内容编号 */
.level1 {
  counter-reset: sidenote-call 0 sidenote-item 0;
}

/* 正文旁注上标编号生成规则 */
.sidenote-number::after {
  counter-increment: sidenote-call;
  content: counter(sidenote-call);
  position: relative;
  top: -.5em;
  font-size: 85%;
  line-height: 0;
  vertical-align: baseline;
}

/* 侧边栏旁注内容编号生成规则 */
.sidenote ol {
  list-style: none;
  padding-left: 0;
}
.sidenote li {
  counter-increment: sidenote-item;
}
.sidenote li p:first-child::before {
  content: counter(sidenote-item) ". ";
  float: left;
  width: 1.5em;
}

如果你使用的主题自定义了章节外层容器类名,将代码中的.level1替换为实际的章节最外层容器类名即可生效。

原有代码错误原因

  1. 计数器重置位置错误:之前在.sidenote ol节点重置计数器,导致每出现一个旁注列表编号就归0,无法在单章内连续计数
  2. 未隐藏默认编号:tufte主题本身会生成默认旁注编号,和你自定义的编号叠加就出现了重复数字、编号错位的问题
  3. 正文和旁注的计数器未同步:两个场景的计数器没有从同一个根节点(章节)同步计数,才会出现正文标1、旁注标2的错位问题

内容的提问来源于stack exchange,提问作者NickCHK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.21 17:15:09