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

如何在Bookdown输出PDF时将二级标题设为左对齐?

Fixing Centered Second-Level Headings to Left-Align in Bookdown PDF

Got it, let's get those second-level headings left-aligned instead of centered. The change needs to happen in the section of your template.tex that defines the formatting for LaTeX's \section command (since Bookdown's ## maps to LaTeX's \section as the second-level heading, assuming you're using a book-style document class like book).

Here's how to do it:

  1. Open your template.tex and locate the heading format definitions
    Look for code related to \titleformat (if your template uses the titlesec package, which is common in Bookdown) or the redefinition of \section.

  2. Modify the centering directive

    • If you find code like this (using titlesec):
      \titleformat{\section}[display]
        {\centering\bfseries\Large}
        {\thesection}{1em}{}
      
      Remove the \centering command, or replace it with \raggedright to explicitly set left alignment:
      \titleformat{\section}[display]
        {\raggedright\bfseries\Large}
        {\thesection}{1em}{}
      
    • If your template uses the default book class without titlesec, look for a \renewcommand{\section} block. It might have \centering somewhere—replace that with \raggedright, like so:
      \renewcommand{\section}{\@startsection{section}{1}{\z@}%
        {-3.5ex \@plus -1ex \@minus -.2ex}%
        {2.3ex \@plus.2ex}%
        {\raggedright\bfseries\Large}}
      
  3. Recompile your Bookdown project
    After saving the modified template.tex, rebuild your PDF. The second-level headings (your ## sections in Markdown) should now be left-aligned instead of centered.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:35:55