I want the pagenumber to display like this:
I have r-markdown like this:
---
LaTeX code here
---
Markdown code here
The actual code:
---
header-includes:
- \usepackage{geometry}
- \usepackage{fancyhdr}
- \usepackage{graphicx}
- \usepackage{xcolor}
- \geometry{
a4paper,
left=15mm,
right=15mm,
headheight=3cm,
top=4cm,
bottom=4.5cm,
footskip=1cm,
}
- \pagestyle{fancy}
- \renewcommand{\headrulewidth}{0.4pt}
- \renewcommand{\footrulewidth}{0.4pt}
- \fancyhead[R]{\includegraphics[width=3.5cm]{logo.png}}
- \fancyfoot[L]{multiple Details \\ multiple Details \\ multiple Details}
- \fancyfoot[C]{multiple Details \\ multiple Details \\ multiple Details}
- \fancyfoot[R]{multiple Details \\ multiple Details \\ multiple Details}
output: pdf_document
---
# Heading level 1
content
## Heading level 2
content
# Heading level 1
content
## Heading level 2
content
My question:
Which package do I use and how is it possible to display my pagenumber like in the screenshot?
To convert the .md file to a .pdf I use pandoc like this:
pandoc --toc readme.md -o readme.pdf
If your distribution is reasonable new (within the last year or so...), you can use the shipout/foreground hook to create such a thumb index for the page number (make sure to compile two times to get the position right):
---
header-includes:
- \usepackage{geometry}
- \usepackage{fancyhdr}
- \usepackage{graphicx}
- \usepackage{xcolor}
- \geometry{
a4paper,
left=15mm,
right=15mm,
headheight=3cm,
top=4cm,
bottom=4.5cm,
footskip=1cm,
}
- \pagestyle{fancy}
- \fancyhead[R]{\includegraphics[width=3.5cm]{example-image-duck}}
- \fancyfoot[L]{multiple Details \\ multiple Details \\ multiple Details}
- \fancyfoot[C]{multiple Details \\ multiple Details \\ multiple Details}
- \fancyfoot[R]{multiple Details \\ multiple Details \\ multiple Details}
- \usepackage{tikzpagenodes}
- \usepackage{lastpage}
- \AddToHook{shipout/foreground}{\begin{tikzpicture}[remember picture,overlay]\node[draw,rotate=90,minimum width=3cm,anchor=north] at (current page text area.east) {\thepage\ / \pageref{LastPage} }; \end{tikzpicture}}
output:
pdf_document:
keep_tex: true
---
# Heading level 1
content
## Heading level 2
content
# Heading level 1
content
## Heading level 2
content
Related
\documentclass{article}
\usepackage{makecell,multirow,tabularx}
\usepackage{graphicx}
\usepackage{xcolor,colortbl}
\usepackage{booktabs}
\usepackage[includefoot,margin=0.30in,headsep=0.0in,bottom=2.3in]{geometry}
\setlength{\headheight}{110pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\definecolor{tamu}{HTML}{500000}
\definecolor{lightgray}{HTML}{e9e7e8}
\usepackage{nicematrix}
\usepackage{booktabs}
\fancyhead[C]{
\begin{NiceTabularX}{\textwidth}{| l | X | l |}[rules/color=tamu,rules/width=1mm]
\CodeBefore
\rowlistcolors{1}{red!15}
\Body
\toprule[1mm]
Experiment Number & Experiment & Date \\[5pt]
& & \qquad / \qquad / \qquad\qquad\qquad \\[5pt]
\midrule[1mm]
Name & Lab Partners & CRN \\[5pt]
& & \\[5pt]
\bottomrule[1mm]
\end{NiceTabularX}
}
\fancyfoot[c]{
\begin{NiceTabularX}{\textwidth}{| X | X | X | X |}[rules/color=tamu,rules/width=1mm]
\CodeBefore
\rowlistcolors{1}{red!15}
\Body
\midrule[1mm]
Signature & Date & TA & Date \\[5pt]
&\qquad\qquad / \qquad\qquad / \qquad\qquad & & \qquad\qquad / \qquad\qquad / \qquad\qquad \\[5pt]
\bottomrule[1mm]
\end{NiceTabularX}
}
\usepackage[T1]{fontenc}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}
\begin{document}
\begin{tcolorbox}[enhanced,fit to height=8.25in,colframe=tamu,arc=0pt,outer arc=0pt,boxrule=1mm]
\end{tcolorbox}
\end{document}
The output of this code makes a 2 paged pdf, but I only want the second page. The first page is unneeded and I was wondering what I'm doing wrong since I think its making a second page since its overflowing, but I am not sure. I think the way I'm making the footer is a bit weird, but maybe I am doing it right, please let me know.
Output (Page 1):
Output (Page 2):
Also, if anyone can answer this I would be very happy. I have no clue why, but the borders seem to be drawn too far? What I mean is the top of the borders and maybe some other spots in the header and maybe footer are too long/bleed over where they should (see image below).
Weird borders:
If you'll look into the .log file, you'll find the following warning
Overfull \vbox (19.15993pt too high) has occurred while \output is active []
This warning is caused by the tcolorbox which is taller than the available space on this page. Latex tries to fix this by moving it to the next page, hoping that if it'll be the very first thing on the page, it might fit.
You can avoid this by making your box a bit smaller, so that it's height is smaller (or equal) to the \textheight:
\documentclass{article}
\usepackage{makecell,multirow,tabularx}
\usepackage{graphicx}
\usepackage{xcolor,colortbl}
\usepackage{booktabs}
\usepackage[includefoot,margin=0.30in,headsep=0.0in,bottom=2.3in,showframe]{geometry}
\setlength{\headheight}{110pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\definecolor{tamu}{HTML}{500000}
\definecolor{lightgray}{HTML}{e9e7e8}
\usepackage{nicematrix}
\usepackage{booktabs}
\fancyhead[C]{
\begin{NiceTabularX}{\textwidth}{| l | X | l |}[rules/color=tamu,rules/width=1mm]
\CodeBefore
\rowlistcolors{1}{red!15}
\Body
\toprule[1mm]
Experiment Number & Experiment & Date \\[5pt]
& & \qquad / \qquad / \qquad\qquad\qquad \\[5pt]
\midrule[1mm]
Name & Lab Partners & CRN \\[5pt]
& & \\[5pt]
\bottomrule[1mm]
\end{NiceTabularX}
}
\fancyfoot[c]{
\begin{NiceTabularX}{\textwidth}{| X | X | X | X |}[rules/color=tamu,rules/width=1mm]
\CodeBefore
\rowlistcolors{1}{red!15}
\Body
\midrule[1mm]
Signature & Date & TA & Date \\[5pt]
&\qquad\qquad / \qquad\qquad / \qquad\qquad & & \qquad\qquad / \qquad\qquad / \qquad\qquad \\[5pt]
\bottomrule[1mm]
\end{NiceTabularX}
}
\usepackage[T1]{fontenc}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}
\begin{document}
\begin{tcolorbox}[enhanced,fit to height=\textheight,colframe=tamu,arc=0pt,outer arc=0pt,boxrule=1mm]
\end{tcolorbox}
\end{document}
The knitr::kable with the latex format option produces a tabular environment.
For example,
# produces a tabular environment
knitr::kable(head(cars),
format = 'latex')
produces
\begin{tabular}{r|r}
\hline
speed & dist\\
\hline
4 & 2\\
\hline
4 & 10\\
\hline
7 & 4\\
\hline
7 & 22\\
\hline
8 & 16\\
\hline
9 & 10\\
\hline
\end{tabular}
The table is not centered. If I use kable_stylying from kableExtra, whose value for the option position defaults to center, I get a centered floating table, using the LaTeX table enviornment.
For example, this
# produces a tabular environment inside a table
knitr::kable(head(cars),
format = 'latex') %>%
kableExtra::kable_styling()
produces
\begin{table}
\centering
\begin{tabular}{r|r}
\hline
speed & dist\\
\hline
4 & 2\\
\hline
4 & 10\\
\hline
7 & 4\\
\hline
7 & 22\\
\hline
8 & 16\\
\hline
9 & 10\\
\hline
\end{tabular}
\end{table}
However, I just want to make a small, almost inline, table. I do not want it to float. I do not want captions, etc. What I want then is something to produce LaTeX code like this:
\begin{center}
\begin{tabular}{r|r}
\hline
speed & dist\\
\hline
4 & 2\\
\hline
4 & 10\\
\hline
7 & 4\\
\hline
7 & 22\\
\hline
8 & 16\\
\hline
9 & 10\\
\hline
\end{tabular}
\end{center}
Is that possible using knitr and kableExtra?
I can use a workaround. For example, use chunk options results='asis', and in the chunk, do
cat("\\begin{center}",sep='\n')
knitr::kable(head(cars),
format = 'latex')
cat("\\end{center}",sep='\n')
However, I would like to know if this it is possible without the workaround and whether I am missing something.
Minimal reproducible example
The following is a minimal working example of an RMarkdown document at produces the three kinds of tables mentioned above. Dependencies are magrittr, knitr, and kableExtra.
---
output: pdf_document
---
```{r}
library(magrittr)
```
This produces a `tabular`, non-floating, table. But it is not centered.
```{r}
knitr::kable(head(cars), format = 'latex')
```
The following code produces a centered table, but using a `table` environment, so it floats (in this case to the top of the page), which is probably what we usually want, but we don't *always* want.
```{r}
knitr::kable(head(PlantGrowth), format = 'latex') %>%
kableExtra::kable_styling()
```
We can produce a centered `tabular` environment using chunk option `results='asis'` etc.
```{r, echo=FALSE, results='asis'}
cat("\\begin{center}",sep='\n')
knitr::kable(head(ToothGrowth),
format = 'latex')
cat("\\end{center}",sep='\n')
```
Rendering this (as a pdf_document) creates a single page pdf with this content:
You just need to set the table.envir argument to "center" to wrap the \tabular in \begin{center} ... \end{center}. In your MRE:
---
output: pdf_document
---
```{r}
library(magrittr)
```
This produces a `tabular`, non-floating, table, and it *is* centered:
```{r}
knitr::kable(head(cars), format = 'latex', table.envir = "center")
```
If you want to wrap it twice (e.g. centered and boldface), you can use something like table.envir = c("bf", "center", "bf"): because kable() isn't smart enough to reverse the order when adding the \end{} markers, you need to use a palindrome.
If you use \centering, you'll avoid the extra vertical spacing from the center environment:
---
output:
pdf_document:
keep_tex: true
header-includes:
- \AddToHook{env/tabular/before}{\begingroup\centering}
- \AddToHook{env/tabular/after}{\par\endgroup}
---
```{r}
library(magrittr)
```
text
```{r}
knitr::kable(head(cars), format = 'latex')
```
text
Many years I've successfully used the tabu-package to create tables like shown in the code-example below. I produced an extended number of those tables in an documentation and so want to avoid major changes.
Since the June update of MiKTeX to Version 21.6 all the tables show the same error-message like:
Row xx Dimension too large. \end{longtabu}
As soon as I use one of the previous MiKTeX Version e.g. 21.3. proper tables are produced.
Are there any ideas what the reason could be and how to circumnavigate the problem?
My code:
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{array}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{longtable}
\usepackage{tabu}
\begin{document}
\begin{spacing}{2}
\begin{longtabu}to\textwidth{lXl}
200 A & & 300 B \\
100 C & & 200 D \\
30 E & & 600 F \\
80 G & & 50 H \\
0,5 I & &3000 J \\
\end{longtabu}
\end{spacing}
\end{document}
How can I autonumber equations in an Rmarkdown document?
I've tried including "\usepackage{mathajax}" in the header, but the equations won't autonumber. I believe I need to configure mathjax, but can't figure out how.
I'm open to any solutions.
Please note, the solution in this post does not work.
Edit:
A simplified example of the desired output is below.
The code for the above image is below. I tried using \begin{equation} and \end{equation} instad of "align";however, the HTML document does not output the formulas correctly.
---
header-includes:
- \usepackage{amsmath}
output:
html_document: default
---
\begin{align}
2+2 = 4 \tag{1} \\
3+2 = 5 \tag{2} \\
4+2 = 6 \tag{3} \\
5+2=7 \tag{4} \\
\end{align}
You can get pretty close by using bookdown::html_document2, c.f. the documentation:
---
output:
bookdown::html_document2: default
---
\begin{align}
2+2 &= 4 \\
3+2 &= 5 (\#eq:three) \\
4+2 &= 6 (\#eq:four) \\
5+2 &= 7 (\#eq:five)
\end{align}
Result:
You get an equation number for every equation where you put a label. I have omitted the label on the first equation to show this effect. This is slightly different from the LaTeX's behavior, where you have to use \notag in an align environment to not get an equation number.
I am trying to compile the following beamer presentation in rmarkdown. But when it tries to render rmarkdown document an error occurs
! LaTeX Error: Option clash for package xcolor.
I searched Internet and found out that I need to include \PassOptionsToPackage{table}{xcolor} before the line \documentclass. Applying options to already loaded package and also see here
How do I do it in RMarkdown?
---
title: "My report"
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage{booktabs}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage[table]{xcolor}
---
```{r setup, include=FALSE}
library(knitr)
library(kableExtra)
knitr::opts_chunk$set(echo = FALSE)
```
```{r positioned_table}
dt <- mtcars[1:5, 1:6]
kable(dt) %>%
kable_styling("striped", full_width = F) %>%
column_spec(5:7, bold = T) %>%
row_spec(3:5, bold = T, color = "white", background = "#D7261E")
```
The resulting .tex file is
\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[ignorenonframetext,]{beamer}
\usepackage{pgfpages}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbolsempty
% Prevent slide breaks in the middle of a paragraph:
\widowpenalties 1 10000
\raggedbottom
\setbeamertemplate{part page}{
\centering
\begin{beamercolorbox}[sep=16pt,center]{part title}
\usebeamerfont{part title}\insertpart\par
\end{beamercolorbox}
}
\setbeamertemplate{section page}{
\centering
\begin{beamercolorbox}[sep=12pt,center]{part title}
\usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
\centering
\begin{beamercolorbox}[sep=8pt,center]{part title}
\usebeamerfont{subsection title}\insertsubsection\par
\end{beamercolorbox}
}
\AtBeginPart{
\frame{\partpage}
}
\AtBeginSection{
\ifbibliography
\else
\frame{\sectionpage}
\fi
}
\AtBeginSubsection{
\frame{\subsectionpage}
}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provides euro and other symbols
\else % if luatex or xelatex
\usepackage{unicode-math}
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\usepackage{hyperref}
\hypersetup{
pdftitle={My report},
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
\newif\ifbibliography
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% set default figure placement to htbp
\makeatletter
\def\fps#figure{htbp}
\makeatother
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage[table]{xcolor}
\title{My report}
\date{}
\begin{document}
\frame{\titlepage}
\begin{frame}
\begin{table}[H]
\centering
\begin{tabular}{l|r|r|r|>{\bfseries}r|>{\bfseries}r|>{\bfseries}r}
\hline
& mpg & cyl & disp & hp & drat & wt\\
\hline
Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 & 2.620\\
\hline
Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 & 2.875\\
\hline
\rowcolor[HTML]{D7261E} \textcolor{white}{\textbf{Datsun 710}} & \textcolor{white}{\textbf{22.8}} & \textcolor{white}{\textbf{4}} & \textcolor{white}{\textbf{108}} & \textcolor{white}{\textbf{93}} & \textcolor{white}{\textbf{3.85}} & \textcolor{white}{\textbf{2.320}}\\
\hline
\rowcolor[HTML]{D7261E} \textcolor{white}{\textbf{Hornet 4 Drive}} & \textcolor{white}{\textbf{21.4}} & \textcolor{white}{\textbf{6}} & \textcolor{white}{\textbf{258}} & \textcolor{white}{\textbf{110}} & \textcolor{white}{\textbf{3.08}} & \textcolor{white}{\textbf{3.215}}\\
\hline
\rowcolor[HTML]{D7261E} \textcolor{white}{\textbf{Hornet Sportabout}} & \textcolor{white}{\textbf{18.7}} & \textcolor{white}{\textbf{8}} & \textcolor{white}{\textbf{360}} & \textcolor{white}{\textbf{175}} & \textcolor{white}{\textbf{3.15}} & \textcolor{white}{\textbf{3.440}}\\
\hline
\end{tabular}
\end{table}
\end{frame}
\end{document}
Using very usefull comment from #samcarter, I found the exact answer. All I need is the following yaml header in my rmarkdown document:
---
title: "My report"
output:
beamer_presentation:
keep_tex: true
classoption: xcolor=table
header-includes:
- \usepackage{booktabs}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
---
To use the table xcolor option with beamer on can pass this to the documentclass. In traditional latex
\documentclass[xcolor={table}]{beamer}
For markdown https://bookdown.org/yihui/rmarkdown/pdf-document.html#latex-options suggests that on can use
classoption: xcolor={table}