Elastic coupling between layers in two-dimensional materials