Peculiar LaTeX issue resolved

Posted at 11:41:54 am by hari under Software and Technology (418 views)

There was a peculiar LaTeX problem that I encountered recently with the tabular environment. Controlling the appearance of vertical lines between columns can be a real problem. It was particularly baffling me because although there is a \cline command to draw horizontal lines spanning between a few columns, there was no corresponding command to draw a vertical line that spans only a few rows. By default, when you create a tabular, you can draw vertical lines between columns, but only if they span the entire length of the table.

You can see what I mean, by looking at this screenshot.

LaTeX tabular environment
As you can see, drawing such a table is not straightforward. It's easy to draw those horizontal lines, but not at all possible to draw vertical lines which don't span the entire table. There was a workaround which I found after asking for help at CQF.info. The solution was to use the \multicolumn command.

Here is the code which produces that effect:

\begin{tabular}{lll}
& X & Y \\
\cline{2-3}
\multicolumn{1}{l|}{Number of bulbs used} & \multicolumn{1}{l|}{100} & \multicolumn{1}{l|}{100} \\
\cline{2-3}
\multicolumn{1}{l|}{Average life (hrs)} & \multicolumn{1}{l|}{1300} & \multicolumn{1}{l|}{1248} \\
\cline{2-3}
\multicolumn{1}{l|}{Standard deviation (hrs)} & \multicolumn{1}{l|}{82} & \multicolumn{1}{l|}{93} \\
\cline{2-3}
\end{tabular}

It's fair to say that LaTeX is not particularly strong when handling tabular material and so you have a lot of additional packages which provide environments such as supertabular, tabularx, longtable and so on. However I am glad that I could resolve this particular issue, although the code involved is much longer since you have to use the \multicolumn command repeatedly. A better solution would definitely be appreciated.

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
:!: :?: :idea: :) :D :p B) ;) :> :roll: :oops: :| :-/ :( :'( |-| :>> :yes: ;D :P :)) 88| :. :no: XX( :lalala: :crazy: >:XX
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)