Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Latex 居中标题不会显示在Rmarkdown的目录中_Latex_R Markdown - Fatal编程技术网

Latex 居中标题不会显示在Rmarkdown的目录中

Latex 居中标题不会显示在Rmarkdown的目录中,latex,r-markdown,Latex,R Markdown,我所在区域的大多数报告的标题都以粗体为中心。我可以通过一个LaTex命令来实现这一点(参见下面的示例) 但是,我非常喜欢Rmarkdown中的目录功能,它在.Rmd文档的非块部分注册任何文本,以至少一个#作为标题,并尽职地将其加粗并放在目录中 问题是这些标题是左对齐的 我想要我的蛋糕,也想吃它。我想要一个中心对齐的标题,显示在目录中 .Rmd脚本说明了下面包含的问题。对此问题的任何解决方案都将不胜感激 --- title: "A Problem With Centering Headings"

我所在区域的大多数报告的标题都以粗体为中心。我可以通过一个LaTex命令来实现这一点(参见下面的示例)

但是,我非常喜欢Rmarkdown中的目录功能,它在.Rmd文档的非块部分注册任何文本,以至少一个
#
作为标题,并尽职地将其加粗并放在目录中

问题是这些标题是左对齐的

我想要我的蛋糕,也想吃它。我想要一个中心对齐的标题,显示在目录中

.Rmd脚本说明了下面包含的问题。对此问题的任何解决方案都将不胜感激

---
title: "A Problem With Centering Headings"
output: pdf_document
toc: yes
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# This Title Shows Up In My TOC

\begin{center}\Large
\textbf{This Title Does Not Show Up in My TOC}
\end{center}

This is some text that is completely irrelevant to the example

我已经阅读了
sectsty
包的文档,就是这样做的

步骤1:在YAML元数据中包含
sectsty

步骤2:在文档开头指定您希望如何在文档中对齐不同的分层标题
allsectionsfont{}
将大括号中的命令应用于第一层节标题(在由单个
#
指定的Rmarkdown中)
subsectionfont{}
将大括号中的命令应用于第二层标题(由
##
指定),而
subsectionfont{}
将同样的操作应用于第三层标题。所有这些标题都会出现在你的TOC中

注意:
\raggedright
左对齐和
\raggedleft
右对齐。不知道为什么,但事实就是这样

请参阅下面的RMarkdown文档

---
title: "No more problems With Centering Headings"
output: pdf_document
toc: yes
header-includes:
   - \usepackage{sectsty}
---

\allsectionsfont{\centering}
\subsectionfont{\raggedright}
\subsubsectionfont{\raggedleft}

# At last my main titles are centered

Now for some irrelevant text. 

## Second Tiered Titles are Automatically Left-aligned

Now for more text

### Third-tiered titles are automatically right-aligned

now some more text

使用LaTeX软件包
titlesec
格式化
\section
命令。或者更简单:
\usepackage{sectsty}
然后
\allsectionsfont{\centralized}
。或者,您可以定义一个新命令,如
\csection
,以创建单中心截面。谢谢@Martin Dabbel Ju Smeller,这非常有用。但是现在所有的标题都居中了。在我对上述问题的描述中,我没有认真考虑我想要什么。我需要能够集中一些标题(即主要章节标题,如简介、方法、结果),但第二和第三层标题保持左对齐。您知道在文档文本中打开和关闭
allsectionsfont{\centering}
函数的命令吗?实际上我自己找到了它。见下面我的答案。再次感谢你。