最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

latex - Not able to create blue caption for my figure - Stack Overflow

programmeradmin1浏览0评论

I'm trying to create blue caption for my figure, but I get the error message

ERROR: 
compilation failed- missing packages (automatic installed disabled)
Undefined control sequence.
<recently read> \DeclareCaptionFont 
                    
l.97 \DeclareCaptionFont
                      {blue}{\color{blue}}

Then I try to render my code. Any ideas why this does not work?

---
title: "test"
format: 
   pdf: 
     include-in-header:
      - text: | 
           \usepackage{geometry}
           \usepackage{color}
           \DeclareCaptionFont{blue}{\color{blue}}
           \usepackage[font=Large,labelfont = bf,textfont = {blue,sf}]{caption}
editor: visual
pdf-engine: lualatex
fig-cap-location: top
lang: nb
---

```{r, figure, fig.height= 12, fig.width= 10,fig.cap=paste("Blue Caption")}
#| echo: false
library(tidyverse)


 data.frame(Year= 2000:2002, 
            length=c(4.2, 10, 29.5)) %>% 
  ggplot() + geom_line(mapping = aes(x = Year, y = length))

```

I'm trying to create blue caption for my figure, but I get the error message

ERROR: 
compilation failed- missing packages (automatic installed disabled)
Undefined control sequence.
<recently read> \DeclareCaptionFont 
                    
l.97 \DeclareCaptionFont
                      {blue}{\color{blue}}

Then I try to render my code. Any ideas why this does not work?

---
title: "test"
format: 
   pdf: 
     include-in-header:
      - text: | 
           \usepackage{geometry}
           \usepackage{color}
           \DeclareCaptionFont{blue}{\color{blue}}
           \usepackage[font=Large,labelfont = bf,textfont = {blue,sf}]{caption}
editor: visual
pdf-engine: lualatex
fig-cap-location: top
lang: nb
---

```{r, figure, fig.height= 12, fig.width= 10,fig.cap=paste("Blue Caption")}
#| echo: false
library(tidyverse)


 data.frame(Year= 2000:2002, 
            length=c(4.2, 10, 29.5)) %>% 
  ggplot() + geom_line(mapping = aes(x = Year, y = length))

```
Share Improve this question edited Mar 7 at 8:49 samcarter_is_at_topanswers.xyz 39.3k5 gold badges59 silver badges78 bronze badges asked Mar 6 at 11:44 stenvik teamstenvik team 1234 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

You need to load the caption package if you want to use macros from this package like \DeclareCaptionFont:

---
title: "test"
format: 
   pdf: 
     include-in-header:
      - text: | 
           \newcommand{\pandocbounded}[1]{#1}
           \usepackage{caption}
           \usepackage{geometry}
           \usepackage{xcolor}
           \DeclareCaptionFont{blue}{\color{blue}}
           \usepackage[font=Large,labelfont = bf,textfont = {blue,sf}]{caption}
editor: visual
pdf-engine: lualatex
fig-cap-location: top
lang: nb
---

```{r, figure, fig.height= 12, fig.width= 10,fig.cap=paste("Blue Caption")}
#| echo: false
library(tidyverse)


 data.frame(Year= 2000:2002, 
            length=c(4.2, 10, 29.5)) %>% 
  ggplot() + geom_line(mapping = aes(x = Year, y = length))

```

发布评论

评论列表(0)

  1. 暂无评论