段落不会缩进

段落不会缩进

我正在使用 rstudio 和 bookdown 将 rmarkdown 交叉编译为 TeX 并为我的论文制作 PDF。我已经按需要格式化了所有内容,但我希望每个段落开头都有缩进。我尝试了indent: truermarkdown yaml 中的设置,并尝试在我的序言中包含此 latex 命令的几个不同变体:setlength\parindent{24pt}\setlength{\parskip}{0.0pt}。我还尝试将该命令移动到 rmarkdown yaml 中的最后in_header一项,因此我认为后续 pkg 覆盖它不会造成问题(但也许我错了)。

生成的pdf:https://github.com/moui72/disStat/blob/master/docs/_main.pdf

有人看到我做错什么了吗?

这是begin{document}生成的 TeX 文件之前的所有内容。

代码块后面是完整 tex 文件、_site.yml、preamble.tex 和 index.Rmd 的链接。今晚我将提供 MWE。

\documentclass[11pt,oneside]{book}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
    \setmainfont[]{Georgia}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\providecommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}

  \title{}
    \pretitle{\vspace{\droptitle}}
  \posttitle{}
    \author{}
    \preauthor{}\postauthor{}
      \predate{\centering\large\emph}
  \postdate{\par}
    \date{2019-09-10}

\pagenumbering{roman}
\usepackage{xcolor}
\usepackage{array}
\usepackage{eqparbox}
\usepackage{stmaryrd}
\usepackage{pdfpages}
\newcommand{\myframebox}[2][Dia]{\setlength{\fboxsep}{2.5ex}\raisebox{\dimexpr-\height + 1.0ex}{\fcolorbox{black}{white}{\eqmakebox[#1]{\enspace #2\enspace}}}}

\setlength\parindent{24pt}\setlength{\parskip}{0.0pt plus 1.0pt}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}

\usepackage[linguistics]{forest}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{setspace}\doublespacing

完整文本文件 https://github.com/moui72/disStat/blob/master/docs/_main.tex

_site.yml(bookdown 用于 rstudio) https://github.com/moui72/disStat/blob/master/drafts/_site.yml

序言.tex https://github.com/moui72/disStat/blob/master/drafts/preamble.tex

索引.Rmd https://github.com/moui72/disStat/blob/master/drafts/index.Rmd

答案1

James 和 Barbara 在评论中解决了我的问题,具体如下:

  1. 包装parskip省略了缩进

  2. 此设置延迟至\AtBeginDocument,因此必须在 之后插入覆盖其设置的尝试\begin{document},否则逆转将不会生效

解决办法很简单,就是将其放在\setlength\parindent{24pt}\setlength{\parskip}{0.0pt plus 1.0pt}后面\begin{document}

问题的根源似乎是 bookdown 默认使用该parskip软件包。正如 Ralf Stuber 在本答案的评论中指出的那样,indent: true应该禁用parskip。当我确定为什么这对我不起作用时,我会更新此答案。

我发布这个答案只是为了防止其他人遇到同样的问题。

相关内容