Created
September 29, 2019 17:17
-
-
Save mrschyte/83cd6c4462470f2bb65a7d324dd8523c to your computer and use it in GitHub Desktop.
Small LaTeX macro to plot bar charts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[a4paper]{article} | |
\usepackage{tikz} | |
\begin{document} | |
\newcommand{\plotbars}[1] | |
{ | |
\begin{tikzpicture} | |
\newcounter{length} | |
\foreach \n [count=\k] in #1 { | |
\stepcounter{length} | |
\foreach \h in {1,...,\n} { | |
\draw (\k * 2,\h) rectangle (\k * 2 + 1,\h + 1); | |
} | |
\node[draw] at (\k * 2 + 0.5, \n + 1.5) {\n}; | |
\node at (\k * 2 + 0.5, 0) {\k}; | |
} | |
\draw (1,0.5) -- (\value{length} * 2 + 2, 0.5); | |
\end{tikzpicture} | |
} | |
\begin{figure} | |
\plotbars{{1,2,3,4,5}} | |
\caption{Barchart 1} | |
\end{figure} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment