Decision Guidanceauto align tidy codes

Don't know which editor is the right one for you? Then this is the place to go!
Post Reply
casperyc
Posts: 50
Joined: Thu Oct 15, 2009 11:23 pm

auto align tidy codes

Post by casperyc »

suppose i input

Code: Select all

Year&Premium&Expenses&Acc.of $P_t-e_t$&Death Cost& \multicolumn{1}{c}{Survival Cost} & \multicolumn{1}{c}{In force expected net $CF$}\\[1.2ex]
$t$&$P_t$&$e_t$&$(P_t-e_t)(10.8)$&$10,000q_{62+t-1}$& \multicolumn{1}{c}{$p_{62+t-1}S_t$} & \multicolumn{1}{c}{$(CF)_t$}\\[1.2ex]
1&3,091,79&92.75&3238.96&101.12&0.00&3137.84\\
2&3,091,79&92.75&3238.96&113.44&0.00&3125.52\\
3&3,091,79&92.75&3238.96&127.16&9872.84&-6761.04
is there any editor would auto matically "tidy" it a bit to

Code: Select all

  {Year} & {Premium} & {Acc.~of $P_t-e_t$} & {Death Cost}        & {Survival Cost}   & {In force expected net $CF$} \\
  {$t$}  & {$P_t$}   & {$(P_t-e_t)(10.8)$} & {$10000q_{62+t-1}$} & {$p_{62+t-1}S_t$} & {$(CF)_t$}                   \\
  \midrule
  1      & 309179    & 3238.96             & 101.12              & 0.00              &  3137.84 \\
  2      & 309179    & 3238.96             & 113.44              & 0.00              &  3125.52 \\
  3      & 309179    & 3238.96             & 127.16              & 9872.84           & -6761.04 \\
i.e. aligne the ‘&' symbol
every time if i have to do manually
it's a pain

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

auto align tidy codes

Post by phi »

With Emacs and AucTeX, you can type

Code: Select all

M-x align RET
to get

Code: Select all

Year & Premium  & Expenses & Acc.of $P_t-e_t$  & Death Cost         & \multicolumn{1}{c}{Survival Cost}   & \multicolumn{1}{c}{In force expected net $CF$} \\[1.2ex]
$t$  & $P_t$    & $e_t$    & $(P_t-e_t)(10.8)$ & $10,000q_{62+t-1}$ & \multicolumn{1}{c}{$p_{62+t-1}S_t$} & \multicolumn{1}{c}{$(CF)_t$}                   \\[1.2ex]
1    & 3,091,79 & 92.75    & 3238.96           & 101.12             & 0.00                                & 3137.84                                        \\
2    & 3,091,79 & 92.75    & 3238.96           & 113.44             & 0.00                                & 3125.52                                        \\
3    & 3,091,79 & 92.75    & 3238.96           & 127.16             & 9872.84                             & -6761.04
casperyc
Posts: 50
Joined: Thu Oct 15, 2009 11:23 pm

auto align tidy codes

Post by casperyc »

Hi there,

I am a windows user. I have just installed those two applications.
and I have no idea how to 'run'

Code: Select all

M-x align RET
could you explain a bit about that if you are a windows user as well?

Thanks.
php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

auto align tidy codes

Post by php1ic »

I use emacs on linux so am assuming it is the same/similar to windows.

To do what phi suggested, highlight the contents of the table then press ALT+x (M-x means press x while holding the meta key, which is often ALT).

You will notice that the cursor has moved to the small bar at the bottom of the emacs window (the minibuffer) where M-x has also been written. If you now type "align" then press enter, the table will become aligned as required.

emacs has quite a steep learning curve to get the basics, but once you know them it is a very powerful tool. It even has a way of inserting tables into latex (almost) graphically. Google has all you will need, but this link shows you the basics of how to create a basic table.

http://xahlee.org/emacs/emacs_table.html
Post Reply