'Knit PDF Output with CAT in R

I am using CAT command in R to get following output.

The Output in knitted PDF file is different to what I get in console. How can I get similar output in PDF as I get in Console ?

In PDF Output, the print question and code output is getting intermingled.

header <- blue$italic

cat(header("\nAre there any Missing Values ? \n"))
anyNA(cars_df)

cat(header("\nHow many Missing Values are there ? \n"))
sum(is.na(cars_df))

cat(header("\nWhich Variables have got Missing Values ? \n"))
colSums(is.na(cars_df))

R Studio Console Output

R Studio Console Output

Knitted PDF Output

Knitted PDF Output



Solution 1:[1]

I had the same issue but with html:

this>

enter image description here

results in this ugly mess >

enter image description here

Solution 1 is to use "hold" instead of "asis":=> enter image description here enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aaron C