[Tex/LaTex] Indenting style of LaTeX files with Sublime Text

indentationsublime-text

Here is a part of my LaTeX code and what I want it to be:

...
\begin{table}
    \begin{tabularx}{\textwidth}{|l|l|l|X|X|X|X|}
... 

However, if I re-indent it in Sublime Text 3, it becomes:

...
\begin{table}
\begin{tabularx}{\textwidth}{|l|l|l|X|X|X|X|}
...

Then the folding function is also invalid, how do I fix this? I'm using LaTeXTools.

Best Answer

You should use the plugin latexindent. Please see here for the documentation and the download.

Here is an example how to use it with arara and how the code looks after the indentation.

% arara: pdflatex
% arara: indent: { overwrite : yes }

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\begin{table}
    \centering
    \begin{tabularx}{\textwidth}{lllXXXX}
        \toprule
        l & l & l & X & X & X & X \\ 
        \bottomrule
    \end{tabularx}
\end{table}
\end{document}
Related Question