A LaTeX Template for Homework

February 19, 2019 - 2 minutes
Miscellaneous LaTeX

Yes, there are already tons of LaTeX templates, why make another one? Well, personally, those templates are good, but not my style. I prefer putting all my solutions inside a box, but a simple box doesn’t look nice enough for me.

Consider that I will use it for a fairly long time, I just made one myself, mainly using the package tcolorbox. In the end, I end up with all my assignment using this template, except for writing a report.

\documentclass{article}
\usepackage[a4paper,left=3cm,right=2cm,top=2.5cm,bottom=2.5cm]{geometry}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{tcolorbox} %use to set solution environment
\tcbuselibrary{skins, breakable}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{booktabs}
\usepackage{enumitem}
%\usepackage{courier}

\newenvironment{solution}{\tcolorbox[enhanced,breakable,colback=white,
    attach boxed title to top left = {yshift = -2mm},title=\textbf{Solution}]}
{\endtcolorbox}
%customized solution environment

\newcommand{\E}{\mathbb{E}}
\newcommand{\EX}[1]{\mathbb{E}\left(#1\right)}
\newcommand{\prob}[1]{\mathbb{P}\left\lbrace #1 \right\rbrace }
\newcommand{\bv}[1]{\mathbf{#1}}
\newcommand{\note}{\textbf{Note: }}
\newcommand{\dint}{\displaystyle\int}
\newcommand{\ind}[1]{1_{\lbrace #1 \rbrace}}
\newcommand{\poi}{\mathrm{Poisson}}

\pagestyle{fancy}
\fancyhf{}
\rhead{id}
\chead{\emph{name}}
\lhead{course code}
\rfoot{ \thepage \text{ of} \pageref{LastPage}}
\setlength{\headsep}{10pt}

\begin{document}
\begin{center}
{\large \textbf{Assignment \# 1}}
\end{center}
\flushleft
\textbf{Q1.(5.2.3) Compounding } \begin{enumerate}[topsep = 0 ex, itemsep=0ex,partopsep=0ex,parsep=0ex,label=(\alph*).]
    \item Let $X$ have the Poisson distribution with parameter $Y$ , where $Y$ has the Poisson distribution with
    parameter $\mu$. Show that $G_{X+Y}(x) = \exp\lbrace\mu(xe^{x-1}-1)\rbrace$.
    \item Let $X_1, X_2,\ldots$ be independent identically distributed random variables with the logarithmic
    mass function
    $$f(k) = \frac{(1-p)^k}{k\ln(1/p)}, k \geq 1,$$
    where $0 < p <1$. If $N$ is independent of the $X_i$ and has the Poisson distribution with parameter $\mu$, show that $Y = \sum_{i=1}^{N}X_i$ has a type of negative binomial distribution.
\end{enumerate}
\begin{solution}
\begin{enumerate}[topsep = 0 ex, itemsep=0ex,partopsep=0ex,parsep=0ex,label=(\alph*).]
\item Given $X\sim \poi(Y), Y \sim \poi(\mu)$, recall generating function of $\poi(\lambda)$ is $G_X(s) = e^{\lambda(s-1)}$.
Now, conditioning on value of $Y$, by the definition of generating function, we have
$$G_{X+Y}(x) = \EX{x^{X+Y}} = \EX{\EX{x^{X+Y}|Y}}= \EX{x^Y\cdot e^{Y(x-1)}} = \EX{(xe^{x-1})^Y} = e^{\mu(xe^{x-1}-1)}$$
\item Since $X_1,X_2,\ldots$ are i.i.d random variables, then they share a common generating function
$$G_{X_1}(s) = \sum_{k=1}^{\infty}s^k\cdot \frac{(1-p)^k}{k\ln(1/p)} = \frac{\ln(1-s(1-p))}{\ln p}$$
Now, by the compounding Theorem, we have
$$G_Y(s) = G_N(G_{X_1}(s)) = \exp\left\{\mu(G_{X_1}(s)-1)\right\} = \left(\frac{1-s(1-p)}{p}\right)^{\mu/\ln p}$$
\note Recall the series of logarithm, $\ln(1-x) = -\sum\limits_{n=1}^{\infty}x^n/n$.
\end{enumerate}
\end{solution}
    
\end{document}