Skip to content

Instantly share code, notes, and snippets.

@fbie
Created August 31, 2016 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbie/7181eae4c64eff7499ede9ead5e7e9cf to your computer and use it in GitHub Desktop.
Save fbie/7181eae4c64eff7499ede9ead5e7e9cf to your computer and use it in GitHub Desktop.
Examples for how to code nice looking (function) spreadsheets in Latex
\documentclass[a4paper]{article}
\usepackage{colortbl} % Defines \columncolor, \multicolumn
\usepackage{pgfplots} % Defines lightgray
\newcolumntype{g}{>{\columncolor{lightgray}}c}
\newcolumntype{f}{>{\columncolor{pink}}c}
\newcommand{\col}[1]{\multicolumn{1}{c|}{#1}}
\begin{document}
A $5 \times 5$ identity matrix:
\begin{tabular}{|g|c|c|c|c|c|c|}
\hline
\rowcolor{lightgray}
& \col{A} & \col{B} & \col{C} & \col{D} & \col{E} & \col{F} \\ \hline
1 & \texttt{1} & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{0} & \\ \hline
2 & \texttt{0} & \texttt{1} & \texttt{0} & \texttt{0} & \texttt{0} & \\ \hline
3 & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{0} & \texttt{0} & \\ \hline
4 & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{0} & \\ \hline
5 & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{= A1:E5} \\ \hline
\end{tabular}
Recursive function to compute the sum of the Fibonacci sequence up to some $n$:
\begin{tabular}{|f|c|c|}
\hline
\rowcolor{pink}
& A & B \\ \hline
1 & & \texttt{= FIB(A1 - 1)} \\ \hline
2 & \texttt{= IF(A1 = 1, 1, B1 + B2)} & \texttt{= FIB(A1 - 2)} \\ \hline
3 & \texttt{= IF(A1 <= 0, 0, A2) } & \texttt{= DEFINE(``FIB'', A3, A1)} \\ \hline
\end{tabular}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment