Dynamic PDF Reports Customize in R Markdown – Receiving the following error “! LaTeX Error: There’s no line here to end.”

So, I am on a project, where the user can select an option and the output pdf should be generated accordingly as a pdf report. The Shiny app does work well and the pdf report too. I would like to just go one step further and customize the pdf report’s styling to make it visually more attractive. To that end, I am pretty much using a similar customized pdf styling that I found online. However, I am having difficulty to apply the customized pdf style, written in .tex, to the dynamic pdf report made with RMarkdown. So, here is a sample code from the R Markdown document;

---
title: "`r unique(data_selected$aaa)` - AAA"
subtitle: BBB
geometry: margin=1in
output:
  pdf_document:
    latex_engine: xelatex
    fig_caption: true
    keep_tex: true
    includes:
      in_header: pdf_report_styling.tex
---

# Header 1

some text here

`{r aaa}

data <- read_excel("data.xlsx")

data_selected <- data %>%
  filter(aaa == data$aaa)

table_gt <- data_selected %>%
  gt() %>%
  tab_style(style = list(cell_fill(color = "lightgray")),
            locations = cells_body(columns = everything())
            )
table_gt

And the .tex file I am using to customize my pdf report is this;

% load packages
usepackage{geometry}
usepackage{xcolor}
usepackage{eso-pic}
usepackage{fancyhdr}
usepackage{sectsty}
usepackage{fontspec}
usepackage{titlesec}

%% Set page size with a wider right margin
geometry{a4paper, total={170mm,257mm}, left=20mm, top=20mm, bottom=20mm, right=50mm}

%% Let's define some colours
definecolor{light}{HTML}{D3D3D3}
definecolor{highlight}{HTML}{800080}
definecolor{dark}{HTML}{330033}

%% Let's add the border on the right hand side 
AddToShipoutPicture{% 
    AtPageLowerLeft{% 
        put(LenToUnit{dimexprpaperwidth-3cm},0){% 
            color{light}rule{3cm}{LenToUnitpaperheight}%
          }%
     }%
     % logo
          }

%% Style the page number
fancypagestyle{mystyle}{
  fancyhf{}
  renewcommandheadrulewidth{0pt}
  fancyfoot[R]{thepage}
  fancyfootoffset{3.5cm}
}
setlength{footskip}{20pt}

%% style the chapter/section fonts
chapterfont{color{dark}fontsize{20}{16.8}selectfont}
sectionfont{color{dark}fontsize{20}{16.8}selectfont}
subsectionfont{color{dark}fontsize{14}{16.8}selectfont}
titleformat{subsection}
  {sffamilyLargebfseries}{thesection}{1em}{}[{titlerule[0.8pt]}]
  
% left align title
makeatletter
renewcommand{maketitle}{bgroupsetlength{parindent}{0pt}
begin{flushleft}
  {sffamilyhugetextbf{MakeUppercase{@title}}} vspace{0.3cm} newline
  {Large {@subtitle}} newline
  @author
end{flushleft}egroup
}
makeatother

%% Use some custom fonts
setsansfont{Ubuntu}[
    Path = fonts/Ubuntu/,
    Scale = 0.9,
    Extension = .ttf,
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    ItalicFont = *-Italic,
    ]
    
setmainfont{keplerstd}[
    Path = fonts/keplerstd/,
    Scale = 0.9,
    Extension = .ttf,
    UprightFont = garr45w,
    BoldFont = bold,
    ItalicFont = italic
    ]

When the dynamic pdf report is tried to be generated the following error occurs;
! LaTeX Error: There's no line here to end.

I appreciate any comments and suggestions to fix the issue. Thank you for your kind attention beforehand.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật