pdf - 渲染为 pdf 时使用四开标题页扩展更改标题大小

标签 pdf latex font-size title quarto

我正在 rstudio 中使用四开本创建一份简短报告,并将其渲染为 pdf。我使用四开标题页扩展来创建带有 Logo 和背景图像的标题页。除了标题字体的大小之外,我可以让一切正常工作。
我已经在网上搜索了几个小时,并尝试了我能想到的所有方法,但标题的字体大小永远不会改变......有人可以提示我做错了什么吗? 这是我的 YAML:

---
title: "Effect of treatment on the species 1"  
author:  "Author 1 and Author 2"  
date: ' `r paste("Date:",Sys.Date())`'  
lang: gl  
format:  
  titlepage-pdf:  
    documentclass: scrbook  
    titlepage: plain  
    titlepage-geometry:  
      - top=70mm  
      - bottom=30mm  
      - right=30mm  
      - left=30mm  
    titlepage-logo: "images/circularNegro.png"  
    titlepage-bg-image: "images/OsTres.png"  
    titlepage-theme:   
      elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]  
      page-fontfamily: "Helvetica Neue"  
      page-align: center  
      title-fontsize: 30  
      title-align: center  
      title-space-after: 3cm  
      author-fontsize: 16  
      author-style: plain  
      logo-align: center  
      logo-size: 4cm  
      logo-space-after: 1cm  
      bg-image-location: "ULCorner"  
      bg-image-size: 21cm 
  pdf:  
    # Fonts  
    mainfont: Helvetica Neue  
    fontsize: 12pt  
    papersize: A4  
    margin-top: 25mm  
    margin-bottom: 25mm  
    margin-left: 25mm  
    margin-right: 25mm  
    toc: true  
    toc-depth: 2  
    toc-title: Táboa de contidos  
editor: visual 
---  

我尝试使用 title-fontsize: 30 和 title-style: "large"但它们都不会改变字体大小。 我还尝试将文档类从article更改为scrartcl和scrbook。 我还简化了所有 YAML,甚至完全删除了 format: pdf: 部分,但标题字体大小从未改变。 我最终尝试通过在 YAML 之后包含以下 block (基于此问题 Change title size and color in Quarto (html output) ),使用 CSS(我不知道)定义标题字体大小:

```{css, echo=FALSE}
.title {
  font-size: 24px;
  font-family: "Helvetica Neue";
}
```

当我这样做时,我收到以下错误:

Unable to locate an installed version of Python 3.

最佳答案

据我了解,title-fontsize 选项对标题字体大小没有任何影响。因为如果我们运行以下命令,

---
title: "Effect of treatment on the species 1"  
author:  "Author 1 and Author 2"  
date: last-modified  
lang: gl  
format:  
  titlepage-pdf:  
    documentclass: scrbook
    titlepage: plain  
    titlepage-geometry:  
      - top=70mm  
      - bottom=30mm  
      - right=30mm  
      - left=30mm  
    titlepage-theme:   
      elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]  
      page-align: center 
      title-fontsize: 50
      title-align: center  
      title-space-after: 3cm  
      author-fontsize: 16  
      author-style: plain  
keep-tex: true
---  

然后检查底层中间tex文件,我们可以看到,

\newcommand{\titleandsubtitle}{
% Title and subtitle
{\fontsize{50}{60.0}\selectfont
{\Large{\nohyphens{Effect of treatment on the species 1}}}\par
}%
}
\newcommand{\titlepagetitleblock}{
\titleandsubtitle
}

因此,标题字体大小实际上是 \Large,而我们指定的字体大小 50 根本没有任何效果。

因此,解决此问题的一种方法是使用 title-fontstyle ,它采用 tinysmalllargeLargeLARGEhuge 、 Huge` 作为字体大小。

---
title: "Effect of treatment on the species 1"  
author:  "Author 1 and Author 2"  
date: last-modified  
lang: gl  
format:  
  titlepage-pdf:  
    documentclass: scrbook
    titlepage: plain  
    titlepage-geometry:  
      - top=70mm  
      - bottom=30mm  
      - right=30mm  
      - left=30mm  
    titlepage-theme:   
      elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]  
      page-align: center 
      title-fontstyle: Huge
      title-align: center  
      title-space-after: 3cm  
      author-fontsize: 16  
      author-style: plain  
---  

title page with Huge title


现在前面提到的 HugeLARGELarge 等字体大小是 LaTeX predefined font sizes 。如果您想使用除这些之外的自定义字体大小,您可以定义一个新的 fontsize 命令,然后将其传递给 title-fontstyle 选项。

因此,我们定义了一个新的字体大小命令 gigantic,字体大小为 70,并在 title-fontstyle: gigantic 中使用它。

---
title: "Effect of treatment on the species 1"  
author:  "Author 1 and Author 2"  
date: last-modified  
lang: gl  
format:  
  titlepage-pdf:  
    documentclass: scrbook
    include-in-header: 
      text: |
        \newcommand{\gigantic}{\fontsize{70}{73}\selectfont}
    titlepage: plain  
    titlepage-geometry:  
      - top=70mm  
      - bottom=30mm  
      - right=30mm  
      - left=30mm  
    titlepage-theme:   
      elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]  
      page-align: center 
      title-fontstyle: gigantic
      title-align: center  
      title-space-after: 3cm  
      author-fontsize: 16  
      author-style: plain  
---  

title page with gigantic title


最后是关于您尝试使用 CSS 的一些评论,

  • 您不能使用 CSS 修改任何将呈现为 pdf 的内容。您必须使用 Latex 命令或 pandoc options

  • 并且您面临该错误,因为您正在使用 css block ,quarto 在渲染文档时将其视为 qmd 文件中的第一个代码块,因此,Quarto 将尝试使用 jupyter 渲染此文档这需要安装python。为了避免这个问题,需要使用 engine: knitr 。但同样,首先渲染为 pdf 格式时不需要 css block 。

关于pdf - 渲染为 pdf 时使用四开标题页扩展更改标题大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75379268/

相关文章:

xml - 如何在XSLT中引用TEI xml文档的lg元素中的n属性来创建LaTeX输出(用于使用reledmac制作PDF)

latex - 是否可以将 TikZ 图提取为图像文件?

c# - 使用 iTextSharp 创建多页 pdf

emacs - 在 emacs 中使用 orgtbl 在 latex 中垂直线条

javafx - 如何在 JavaFX SceneBuilder 中更改 gui 字体大小?

wpf - 您如何让 Silverlight 调整文本内容的大小以适合?

html - CSS:em 值是最重要的

vba - 是否可以从excel创建可填写的PDF?

c# - ITextSharp HTML 到 PDF 转换 CSS 图像在转换后不显示

html - PDF 和 HTML 中显示的字体不同