With quarto how can I right-left center align (justify) contents within a column in a two column display - quarto

I have a two column display in quarto. What do I add to right-left center (justify) content within each of the columns? Here is the basic code:
---
title: "uncentered"
---
:::: {.columns}
::: {.column width="50%"}
content
x
content
:::
::: {.column width="50%"}
y
content
y
:::
::::
From the pandoc docs I see I can use align=center in beamer but I just want a basic html page.

If you want to tweak things in html, you can use css rules as a last resort.
Try this
---
title: "uncentered"
format: html
engine: knitr
---
```{css echo=FALSE}
.column {
text-align: center;
}
```
:::: {.columns}
::: {.column width="50%"}
content
x
content
:::
::: {.column width="50%"}
y
content
y
:::
::::
Also take note of that engine: knitr in yaml. Since Here the very first thing was used a css code, Quarto will try to render this file using jupyter engine. So I have specified engine: knitr just to be in a safe side.

Related

Pandoc Column Width for Twocolumn not working

I cannot get column width recognized. It is as if it is just ignored and each column is exactly 50% of the available space. Additionally the example implies I can tell it when I want the 2nd column to start but that is also ignored.
The following is from the Pandoc manual column example, but when I compile it via pandoc they are just each 50% width not what is specified. The frontmatter in my example was not provided in their example but its what I figure it must be to get the columns working. I've tried this with and without the frontmatter.
I'm using ubuntu 18.04 within WSL2 and pandoc version:
pandoc 2.17.1.1 Compiled with pandoc-types 1.22.1, texmath 0.12.4,
skylighting 0.12.2, citeproc 0.6.0.1, ipynb 0.2
I'm using these command line entry for compiling it: (I've also tried pdflatex engine as well)
pandoc mat_doc.md --pdf-engine=xelatex -o mat_doc.pdf
Here is the file:
---
output: pdf_document
classoption: twocolumn
---
:::::::::::::: {.columns}
::: {.column width="60%"}
contents
:::
::: {.column width="40%"}
contents
:::
::::::::::::::
How do I get different sized columns? Why does this not work per their manual? Thx!
The beamer columns you are trying to use, are something special in the beamer class and don't work with normal classes.
However under the hood, these columns are just glorified minipages - and these you can use in normal latex classes.
---
output: pdf_document
---
\noindent\begin{minipage}{.6\textwidth}
test
\end{minipage}
\begin{minipage}{.4\textwidth}
test
\end{minipage}

Figure is alone on a page, even when there's enough space on the previous one

I'm writing my dissertation in Markdown and it includes a lot of figures in the "results" section. Since I really need all the figures and tables to stay in their order and subsection, I'm keeping them in place with \floatplacement{figure}{H} in the YAML for the figures and kable_styling(latex_options = c("hold_position") for the tables.
My question is, if there's a way to have the text float around the figures without the figures changing their order/section? As soon as I set the floatplacement to h instead of H, they are not staying in their section anymore.
I tried , out.width="1\\textwidth", wrapfigure = list("C", 1) in the code chunk options, which makes the text go on the top of the figure (which is good), but puts the figure ond the next page, even though there would be enough space for it on the current page:
My YAML:
---
output:
bookdown::pdf_document2:
toc: no
fig_caption: yes
includes:
in_header: header.tex
lang: de
geometry: "left=3cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
fontsize: 12pt
bibliography: library.bib
csl: science-modified1.csl
link-citations: yes
linkcolor: black
urlcolor: black
header-includes:
- \usepackage{placeins} #definiert den Befehl \FloatBarrier
- \usepackage{fancyhdr}
- \usepackage[doublespacing]{setspace}
- \usepackage{chngcntr}
- \counterwithout{figure}{section}
- \counterwithout{table}{section}
- \usepackage{microtype}
- \usepackage{amsmath}
- \usepackage{float}
- \floatplacement{figure}{H}
- \usepackage{wrapfig}
- \setlength{\parindent}{1cm}
---
My code chunk options of the figure:
```{r, include = F}
defOut <- knitr::knit_hooks$get("plot") # save the default plot hook
knitr::knit_hooks$set(plot = function(x, options) { # set new plot hook ...
x <- defOut(x, options) # first apply the default hook
if(!is.null(options$wrapfigure)) { # then, if option wrapfigure is given ...
# create the new opening string for the wrapfigure environment ...
wf <- sprintf("\\begin{wrapfigure}{%s}{%g\\textwidth}", options$wrapfigure[[1]], options$wrapfigure[[2]])
x <- gsub("\\begin{figure}", wf, x, fixed = T) # and replace the default one with it.
x <- gsub("{figure}", "{wrapfigure}", x, fixed = T) # also replace the environment ending
}
return(x)
})
```
```{r figure-USB-J01-DDD-absolut-line, fig.cap = "Absoluter Verbrauch von J01-Antibiotika DDDs am USB (auf 30 Tage normiert)", out.width="1\\textwidth", wrapfigure = list("C", 1)}
```
Is there a way to let the text go on top of the figure (e.g. if there is space for it on the previous page, but not the figure) without the figures leaving their sections or behaving weirdly like they did in my example?

R markdown alignment with Latex equations

I am trying to produce a PDF document with R markdown which includes some equations and r code. I am trying to align sub-items in an un-ordered list which appear after the equations.
Below is the code. I want the words Prediction and Inference to start as new sub items.
---
title: "Test"
author: "Author"
date: "21 April 2018"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
* Main Point
+ **Prediction** - Some text here
$$
\hat{Y}=\hat{f(X)}+\epsilon ............... (2.2)
$$
$$
E( Y - \hat{Y} )^2
= E[f(X) + \epsilon - \hat{f(X)}]^2
=[f(X) - \hat{f(X)}]^2+Var(\epsilon) ......... (2.3)
$$
+ **Inference** - Some text here
No matter what spacing I try, nothing seems to be working. Currently, after the "Main Point", I have given two tabs before the "+" before "Prediction". This works absolutely fine and produces the sub item of the "Main Point". However, after the two equations when I try the same formatting that I did for the first sub-item, it does not work at all and produces the alignment as shown in the picture.
Markdown has a few rules to make sublists work. Most importantly in your case, sub-items only work if there is a parent item to it. As Stackoverflow uses the same syntax, we can show the examples inline. For example:
1. Item
2. Item
* Mixed
* Mixed
Item
Item
Mixed
Mixed
In your case, you have put some none list items between the sub-items, as follows:
1. Item
2. Item
* Mixed
Some Text
* Mixed
Item
Item
Mixed
Some Text
* Mixed
As you can see, the list has been broken and is not recognised as an item.
Workaround
If you are only using PDF output, you are able to use LaTeX commands to achieve custom styling. In your case, you can use the hspace command to add a separation:
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
* Main Point
\hspace{1cm} + **Prediction** - Some text here
$$
\hat{Y}=\hat{f(X)}+\epsilon ............... (2.2)
$$
$$
E( Y - \hat{Y} )^2
= E[f(X) + \epsilon - \hat{f(X)}]^2
=[f(X) - \hat{f(X)}]^2+Var(\epsilon) ......... (2.3)
$$
\hspace{1cm} + **Inference** - Some text here

how to include pdfpages in rmarkdown for beamer output

I am creating pdf slides using rmarkdown and beamer. When using latex instead of rmarkdown, I can include arbitrary pages from pdf files into my slides with
\usepackage{pdfpages}
...
\includepdf[pages={1-10}]{another_file.pdf}
Is it possible to achieve this with rmarkdown? Note that when just issuing the \includepdf command, intended to be located between slides, pandoc wraps it between \begin{frame} and \end{frame}.
Not a perfect solution but it works (adapted from https://tex.stackexchange.com/questions/11458/error-when-inserting-a-pdf-page-into-a-beamer-presentation?newreg=10fd6a4a46c642118eb4ec905cf87303): use \includegraphics instead of includepdf. This works inside of frames but you have to manyally create a frame for each page you want to insert as it only allows to insert a single page at time.
---
title: "Foo"
output:
beamer_presentation:
---
# Stolen image
---
\includegraphics[page=1,width=\paperwidth]{lecture-1-terminal.pdf}
# My own work
## My slide 1
Great stuff!
In rmarkdown you can use pdfpages like this:
---
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage{pdfpages}
- \setbeamercolor{background canvas}{bg=}
- \makeatletter\beamer#ignorenonframefalse\makeatother
---
test
``` {=latex}
\end{frame}
\includepdf[pages=1-10]{example-image-duck}
\begin{frame}
```
test
(the line \setbeamercolor{background canvas}{bg=} is necessary for beamer versions < 3.64, a patch has been added in 9e3bb9)
As you mentioned, you can inlcude raw TeX in Pandoc Markdown. For me the following works:
$ pandoc -t beamer
foo
\includepdf[pages={1-10}]{another_file.pdf}
bar
^D
which results in:
\begin{frame}
foo
\includepdf[pages={1-10}]{another_file.pdf}
bar
\end{frame}
Maybe you need to update your pandoc version? (I'm currenlty using 2.0 from pandoc nightlies)

Slides with Columns in Pandoc

I would like to have code and an image side-by-side in a Beamer slide.
In LaTeX I would do this with columns. I would like to use markdown within the column structure.
\begin{columns}
\column{.5\textwidth}
~~~~~~~~Python
>>> some python code
~~~~~~~
\column{.5\textwidth}
![](A_generated_image.pdf)
\end{columns}
Unfortunately Pandoc doesn't process the markdown within the \begin{columns} and \end{columns} statements. Is there a way around this?
Is there a way to use markdown within inlined LaTeX?
Is there a pure markdown solution?
Current versions of pandoc (i.e., pandoc 2.0 and later) supports fenced divs. Specially named divs are transformed into columns when targeting a slides format:
# This slide has columns
::: columns
:::: column
left
::::
:::: column
right
::::
:::
Pandoc translates this into the following LaTeX beamer code:
\begin{frame}{This slide has columns}
\protect\hypertarget{this-slide-has-columns}{}
\begin{columns}[T]
\begin{column}{0.48\textwidth}
left
\end{column}
\begin{column}{0.48\textwidth}
right
\end{column}
\end{columns}
\end{frame}
This is simple and has the additional advantage of giving similar results when targeting other presentational formats like reveal.js.
More than two columns work out of the box for Beamer output. Powerpoint, however, only supports two columns. For reveal.js, the widths of three or more columns must be given explicitly:
::: columns
:::: {.column width=30%}
left
::::
:::: {.column width=30%}
middle
::::
:::: {.column width=30%}
right
::::
:::
The problem is that pandoc ignores markdown if it finds a \begin{}. An alternative is to edit the beamer template and add the following:
\newcommand{\columnsbegin}{\begin{columns}}
\newcommand{\columnsend}{\end{columns}}
And write it like this:
\columnsbegin
\column{.5\textwidth}
~~~~~~~~Python
>>> some python code
~~~~~~~
\column{.5\textwidth}
![](A_generated_image.pdf)
\columnsend
I hope still valuable. I made a Pandoc filter in Python to put columns easily, so you can write your presentations in this way:
# Hello World
[columns]
[column=0.5]
~~~python
if __name__ == "__main__":
print "Hello World"
~~~
[column=0.5]
This is how a "Hello World" looks like in Python
[/columns]
that the filter will convert each markup to \begin{columns} and \column{.5\textwidth}, so, the document above will turn in
\begin{frame}[fragile]{Hello}
\begin{columns}
\column{0.5\textwidth}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{some python code}
\end{Highlighting}
\end{Shaded}
\column{0.5\textwidth}
Hello World
\end{columns}
\end{frame}
The code filter is here
import pandocfilters as pf
def latex(s):
return pf.RawBlock('latex', s)
def mk_columns(k, v, f, m):
if k == "Para":
value = pf.stringify(v)
if value.startswith('[') and value.endswith(']'):
content = value[1:-1]
if content == "columns":
return latex(r'\begin{columns}')
elif content == "/columns":
return latex(r'\end{columns}')
elif content.startswith("column="):
return latex(r'\column{%s\textwidth}' % content[7:])
if __name__ == "__main__":
pf.toJSONFilter(mk_columns)
If you never use a pandoc filter, just save the filter to the same document location as columnfilter.py (or other name you want) and run
pandoc -t beamer --filter columnfilter.py yourDocument.mkd
And enjoy!
Beamer Specific Answer. I ran across a solution when attempting to add multiple columns for Pandoc in a regular document. It works here as well, though it does constrain you to Beamer; though that is your use case.
In the slide deck, insert once:
---
header-includes:
- \newcommand{\hideFromPandoc}[1]{#1}
- \hideFromPandoc{
\let\Begin\begin
\let\End\end
}
---
Then add content thus:
\Begin{columns}
\Begin{column}{0.3\textwidth}
Res ipsum loquiter, sed in inferno decit?
\End{column}
\Begin{column}{0.3\textwidth}
Res ipsum loquiter, sed in inferno decit?
\End{column}
\Begin{column}{0.3\textwidth}
Res ipsum loquiter, sed in inferno decit?
\End{column}
\End{columns}
Creating the "hideFromPandoc" command lets you insert begin/end statements throughout without depriving you of markdown in the block.
Fenced Div Answer. There's an answer above that refers to fenced divs. I commented that the answer only works with two columns. It breaks down with more. Here is how that answer works with multiple divs:
::: {.columns}
:::: {.column width=0.3}
Test
::::
:::: {.column width=0.3}
Test
::::
:::: {.column width=0.3}
Test
::::
:::
To get this answer, I had to look at the commit that added the column feature specifically.
You could use FletcherPenney MultiMarkdown which can process markdown to LaTeX/Beamer. Compared to Pandoc, MultiMarkdown has not so many features. However, especially when working with LaTeX it has the advantage that you can embed LaTeX code directly into the Markdown in HTML comments.
Your code would look like this:
<!-- \begin{columns} -->
<!-- \column{.5\textwidth} -->
>>> some python code
<!-- \column{.5\textwidth} -->
![](A_generated_image.pdf)
<!-- \end{columns} -->
For me this solution works fine. With a good editor (e.g. Scrivener, Sublime Text) you can write the latex code without all the comments and find/replace them after editing. In addition, the Metadata support in Multimarkdown is much more flexible, so that it is easier to customize presentations.
In the meantime, I hope that the Pandoc team provides a solution to this problem. I think there are some users who would like to embed small LaTex code particles throughout their markdown documents without having them converted/escaped.
You can use MultiMarkDown comments ( "<!-- Your LaTeX Code inside -->" ) with Pandoc when you enclose the Pandoc command in which you transform your markdown to LaTeX with two sed commands.
In the first sed run, you change the MultiMarkDown comments to "\verb+AAAAAAALaTeX-StuffZZZZZZ+". Then you transform to LaTeX with Pandoc as usual, everything inside "\verb+AAAAAAALaTeX-StuffZZZZZZZ+" is left alone. Then you run sed on the TeX-File and delete the "\verb+AAAAAAA" and "ZZZZZZ+" unfolding your LaTeX code.
The first sed command line before the Pandoc transformation could look like this:
sed -E -e "s/<\\!--(.+)--\\>/\\\\verb\+AAAAAAA\1ZZZZZZZ\+/g " \
source.md > source.i.md
Then use Pandoc on source.i.md as usual to create source.tex. Second sed run like this:
sed -E -e "s/\\\\verb\+AAAAAAA(.+)ZZZZZZZ\+/\1/g" -i "" source.tex
I automated everything in a Makefile so that I can make more changes e.g. to table definitions in one step. On first glance this approach works fine (tested it on column definitions with the beamer class).
With this little sed scripts, you can use all the nice things from Pandoc. You need only to mmd-comment those TeX and LaTeX commands which become either escaped or enclose larger parts of your Markdown.

Resources