5

I am new to Tex and using below code to create a long table. I am creating a book using this where each verse's words are explained in the table format shown below. my document has large number of such tables.

\begin{longtable}{p{1.5cm}p{0.05cm}p{3.5cm}|p{1.5cm}p{0.05cm}p{3.5cm}|p{1.5cm}p{0.05cm}p{3.5cm}}

\end{longtable}

I was wondering if there is a way to shorten it with 1.5cm & 3.5 cm being variables and 0.05 cm as constant cells. This is just a flexibility for later editing. I tried to write something like this.

\newcommand{\ltb}[6]{\begin{longtable}{p{#1cm}p{0.05cm}p{{#2}cm}|p{{#3}cm}p{0.05cm}p{{#4}cm}|p{{#5}cm}p{0.05cm}p{{#6}cm}}}

but could not get any success. I was not sure what I was doing either, just a try. I am attaching a screenshot of how the table looks like. thanks for your helpenter image description here

3
  • 1
    Will the variable lengths vary for each table? Or is this just to allow you to play with different lengths, and all the variable lengths will end up has having some fixed value at the end? Also, will the second column always contain an = sign?
    – Alan Munn
    Aug 20, 2011 at 22:54
  • @Alan, Typically the length will not vary but for any given verse lets say the explanation is longer than the word then I should be able to change it for that particular instance. thats why I did not want to do hard code the length. Yes the second column will always contain "=" sign
    – Aku
    Aug 21, 2011 at 2:53
  • Will the widths for the three columns for the words and the three columns for their explanations be the same or do you want then to vary? Aug 21, 2011 at 3:16

2 Answers 2

7

In addition to Werner's suggestion, you can also use the @{decl.} syntax (which suppresses inter-column space and inserts decl. instead) so you don't have to explicitly typeset the equal signs in the rows of the table:

\documentclass{article}
\usepackage[margin=1cm]{geometry}% just to make room for the table
\usepackage{longtable}

\newlength\word
\newlength\worddef
\newlength\eqsep
\setlength\word{1.5cm}% Word width is 1.5cm
\setlength\worddef{3.5cm}% Word definition width is 3.5cm
\setlength\eqsep{\tabcolsep}% Space before and after the equal sign

\begin{document}

\begin{longtable}{p{\word}@{\hspace{\eqsep}=\hspace{\eqsep}}p{\worddef}|p{\word}@{\hspace{\eqsep}=\hspace{\eqsep}}p{\worddef}|p{\word}@{\hspace{\eqsep}=\hspace{\eqsep}}p{\worddef}}
word1  & some text & word2  & some text  & word3  & some text  \\
word4  & some text & word5  & some text  & word6  & some text  \\
\end{longtable}

\end{document}

enter image description here

5

Yes, you can define lengths to your own liking, storing them in "variables". For example,

\newlength{\word}%
\newlength{\equal}%
\newlength{\worddef}%
\setlength{\word}{1.5cm}% Word width is 1.5cm
\setlength{\equal}{0.05cm}% Equal sign width is 0.05cm
\setlength{\worddef}{3.5cm}% Word definition width is 3.5cm

and then use

\begin{longtable}{p{\word}p{\equal}p{\worddef}|p{\word}p{\equal}p{\worddef}|p{\word}p{\equal}p{\worddef}}
  ...
\end{longtable}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .