From d30570aa23c8125d7cf4e54c76afdccfc5957e73 Mon Sep 17 00:00:00 2001
From: Oleh Krehel <ohwoeowho@gmail.com>
Date: Thu, 10 Oct 2013 10:09:11 +0200
Subject: [PATCH] Add indentation for tabular environment.

* latex.el: add `LaTeX-indent-tabular' to `LaTeX-indent-environment-list'
---
 latex.el | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/latex.el b/latex.el
index f59168f..5df5ce4 100644
--- a/latex.el
+++ b/latex.el
@@ -2633,7 +2633,7 @@ consideration just as is in the non-commented source code."
     ("tabbing")
     ("table")
     ("table*")
-    ("tabular")
+    ("tabular" LaTeX-indent-tabular)
     ("tabular*"))
     "Alist of environments with special indentation.
 The second element in each entry is the function to calculate the
@@ -5996,6 +5996,25 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
       (replace-match "\\\\input{" nil nil)))))
   (TeX-normal-mode nil))
 
+(defun re-search-backward->column (str)
+  (save-excursion
+    (if (re-search-backward str nil t)
+        (current-column)
+      0)))
+
+(defun LaTeX-indent-tabular ()
+  (let ((beg-col (re-search-backward->column "\\\\begin{tabular}")))
+    (if (looking-at "\\\\end{tabular}")
+        beg-col
+      (+ 2
+         (if (looking-at "\\\\\\\\")
+             beg-col
+           (let ((any-col (re-search-backward->column
+                           "\\\\begin{tabular}\\|\\\\\\\\\\|&")))
+             (if (equal "&" (match-string-no-properties 0))
+                 any-col
+               beg-col)))))))
+
 (provide 'latex)
 
 ;;; latex.el ends here
-- 
1.8.4

