Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Last active October 30, 2023 21:42
Show Gist options
  • Save andrewheiss/4ece621813a27dfdcaef7f1c2d773237 to your computer and use it in GitHub Desktop.
Save andrewheiss/4ece621813a27dfdcaef7f1c2d773237 to your computer and use it in GitHub Desktop.
---
title: "tikz in Quarto!"
format: html
---
```{r include=FALSE}
# Necessary for using dvisvgm on macOS
# See https://www.andrewheiss.com/blog/2021/08/27/tikz-knitr-html-svg-fun/
Sys.setenv(LIBGS = "/usr/local/share/ghostscript/9.53.3/lib/libgs.dylib.9.53")
font_opts <- list(dvisvgm.opts = "--font-format=woff")
```
```{tikz complete-pooling, engine.opts=font_opts}
#| echo: false
#| fig-cap: "Complete pooling"
#| fig-align: center
#| fig-ext: svg
#| out-width: 100%
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{tikzpicture}[{every node/.append style}=draw]
\node [rectangle] (pop) at (0, 4) {Population};
\node [ellipse] (y1) at (-5, 2.5) {$y_1$};
\node [ellipse] (y2) at (-3, 2.5) {$y_2$};
\node [ellipse] (y3) at (-1, 2.5) {$y_3$};
\node [ellipse] (y4) at (1, 2.5) {$y_4$};
\node [ellipse, draw=white] (ydots) at (3, 2.5) {$\dots$};
\node [ellipse] (yn) at (5, 2.5) {$y_n$};
\draw [-latex] (pop) to (y1);
\draw [-latex] (pop) to (y2);
\draw [-latex] (pop) to (y3);
\draw [-latex] (pop) to (y4);
\draw [-latex, dashed] (pop) to (ydots);
\draw [-latex] (pop) to (yn);
\end{tikzpicture}
```
@sebacea
Copy link

sebacea commented Oct 30, 2023

Nice gist, any idea on the use of pgfplots package? like the examples here. For a $\LaTeX$ document it is straightforward to include in the headers but for HTML output I do not know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment