You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bookdown无编号前言章节页面标题显示异常问题求助

Hey there! Let’s work through that wonky preface heading issue in your bookdown project. You mentioned the unnumbered # Preface {-} shows up correctly in the table of contents but looks off on the actual page—here are the most common fixes to get it sorted:

  • Check your LaTeX template (for PDF output)
    If you’re building a PDF, unnumbered chapters use LaTeX’s \chapter* command under the hood. Sometimes custom templates or preamble tweaks can mess with its styling.

    • If you’re using a custom LaTeX template, double-check that it properly formats \chapter* headings (font size, spacing, alignment should match regular numbered chapters).
    • If you don’t have a custom template, add this to your preamble.tex file to reset the unnumbered chapter heading style:
      \makeatletter
      \renewcommand{\@makeschapterhead}[1]{
        \vspace*{50\p@}%
        {\parindent \z@ \raggedright \normalfont
          \Huge \bfseries #1\par\nobreak
          \vskip 40\p@
        }
      }
      \makeatother
      

    You can adjust the 50\p@ and 40\p@ values to tweak top/bottom spacing as needed.

  • Tweak CSS for HTML output
    For HTML books, unnumbered headings get the .unnumbered CSS class. If it’s looking out of place, add custom styling to your style.css file to match your regular chapter headings. For example:

    .unnumbered {
      font-size: 2.5rem;
      font-weight: 700;
      margin-top: 2em;
      margin-bottom: 1em;
      color: #2c3e50;
    }
    

    Match the values to whatever you’re using for your numbered h1 headings to keep things consistent.

  • Verify your bookdown settings
    Pop open your _bookdown.yml file and make sure there aren’t any settings overriding chapter numbering behavior. For example:

    • Ensure chapter_numbering: true is set (it’s default, but worth checking).
    • If you have custom output configurations for pdf_book, add keep_tex: true to generate the raw .tex file. You can then check if the Preface is correctly rendered as \chapter*{Preface} without any extra code messing with it.
  • Test with a minimal project
    Sometimes conflicts from other chapters or custom code can cause odd behavior. Try creating a tiny test project with just:

    ---
    title: "Test Book"
    

documentclass: book

Preface {-}

This is the preface.

Chapter 1

This is chapter 1.

Compile this—if the preface looks normal here, you can gradually add back sections from your original book to pinpoint what’s causing the styling issue.

内容的提问来源于stack exchange,提问作者Melinda Higgins
相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:12:34