Fandom

Vim Tips Wiki

Create LaTeX Tables

Redirected from VimTip1610

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 1610 Printable Monobook Previous Next

created 2008 · complexity basic · version 7.0


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

$ cpan LaTeX::Table

Then for example, enter the following into a buffer:

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

Now visually select the lines (for example, ggVG), and enter the command !ltpretty to filter the text through the ltpretty script. The lines are 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}

CommentsEdit

A similar alternative is the ViLaTaC script that can be downloaded from https://github.com/tannhuber/vilatac. It provides individual column formatting with a very simple syntax. However, it is intended for publishing. Thus, colorful themes are not supported.

Also on Fandom

Random Wiki