Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have many longtable's in my document. Everything is the same across all the tables, except for the caption and the content (of course). How can I avoid duplicating the stuff required to set up longtable? Is this possible?

The code needed to produce one table is below. You can see there is a lot of stuff required to set up the table. I would like to avoid duplicating this stuff multiple times.

\begin{longtable}[h]{M{2.00in}M{0.85in}m{0.55in}m{0.55in}m{0.55in}m{0.55in}}
\caption{First Ministry in Jerusalem} \\
\toprule
Event & Location & Matt. & Mark & Luke & John  \\
\midrule
\endfirsthead
\caption{First Ministry in Jerusalem (continued)} \\
    \toprule
    Event & Location & Matt. & Mark & Luke & John \\
    \midrule
\endhead
    \bottomrule
    \multicolumn{6}{r}{\emph{Continued on next page}}
\endfoot
    \bottomrule
\endlastfoot
Content & Goes & Here
\end{longtable}
share|improve this question
    
Welcome to TeX.sx. Note that you don't need to sign your message, as your (nick)name appears at its bottom. –  egreg Jul 15 '11 at 13:51
add comment

1 Answer

up vote 6 down vote accepted

This goes in the preamble:

\newenvironment{mylongtable}[1]
 {\begin{longtable}{M{2.00in}M{0.85in}m{0.55in}m{0.55in}m{0.55in}m{0.55in}}
  \caption{#1} \\
    \toprule
    Event & Location & Matt. & Mark & Luke & John  \\
    \midrule
  \endfirsthead
    \caption{First Ministry in Jerusalem (continued)} \\
    \toprule
    Event & Location & Matt. & Mark & Luke & John \\
    \midrule
  \endhead
    \bottomrule
    \multicolumn{6}{r}{\emph{Continued on next page}}
  \endfoot
    \bottomrule
  \endlastfoot}
 {\end{longtable}}

Then you'll simply write

\begin{mylongtable}{First Ministry in Jerusalem}
<contents>
\end{mylongtable}
share|improve this answer
    
I knew it couldn't be too difficult. Thanks for showing me how! –  Jeremy Jul 18 '11 at 13:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.