Vim Tips Wiki
Advertisement

Typesetting LaTeX tables is time consuming and can get very complicated. It is, however, very easy to use the Perl [LaTeX::Table][1] Module from within VIM. Install the module with

$ cpan LaTeX::Table

Then for example, type following code in VIM and select the lines in VISUAL LINE mode:

theme=NYC;caption_top=1;caption=Bla
Animal & Description & Price
Gnat & per gram & 13.65 
& each & 0.02 
Gnu & stuffed & 92.59

Now type ":!ltpretty". The text is then replaced with the following LaTeX code:

 % theme=NYC;caption_top=1;caption=Bla 
 % Animal & Description & Price
 % Gnat & per gram & 13.65
 % & each & 0.02
 % Gnu & stuffed & 92.59

\definecolor{latextbl}{RGB}{78,130,190}
\begin{table}
\centering
\caption{Bla}
\setlength{\extrarowheight}{1pt}
\begin{tabular}{|llr|}
\hline
\rowcolor{latextbl}\multicolumn{1}{|>{\columncolor{latextbl}}c}{\color{white}\textbf{Animal }} & \multicolumn{1}{>{\columncolor{latextbl}}c}{\color{white}\textbf{ Description }} & \multicolumn{1}{>{\columncolor{latextbl}}c|}{\color{white}\textbf{ Price}} \\
\hline
\rowcolor{latextbl!25}Gnat & per gram & 13.65 \\
\rowcolor{latextbl!10}     & each     & 0.02  \\
\rowcolor{latextbl!25}Gnu  & stuffed  & 92.59 \\
\hline
\end{tabular}
\end{table}
Advertisement