如何在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:
Open your
template.texand locate the heading format definitions
Look for code related to\titleformat(if your template uses thetitlesecpackage, which is common in Bookdown) or the redefinition of\section.Modify the centering directive
- If you find code like this (using
titlesec):
Remove the\titleformat{\section}[display] {\centering\bfseries\Large} {\thesection}{1em}{}\centeringcommand, or replace it with\raggedrightto 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\centeringsomewhere—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}}
- If you find code like this (using
Recompile your Bookdown project
After saving the modifiedtemplate.tex, rebuild your PDF. The second-level headings (your##sections in Markdown) should now be left-aligned instead of centered.
内容的提问来源于stack exchange,提问作者Minyi Han

