Created
August 31, 2016 03:46
-
-
Save fbie/7181eae4c64eff7499ede9ead5e7e9cf to your computer and use it in GitHub Desktop.
Examples for how to code nice looking (function) spreadsheets in Latex
This file contains 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{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