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 the following problem with my table:

The height of the 2nd row is slightly too small and the text overlaps with the line at the bottom and the top of the cell. My code is below:

\begin{longtabu} to \linewidth {| m{0.41\textwidth} | m{0.53\textwidth} |}
\hline
\multicolumn{1}{|c}{Static (stuff)} & \multicolumn{1}{|c|}{Dynamic (stuff)} \\ \hline
\endhead
\hline
\endfoot
\endlastfoot 
textetxtetxtexttext & textetxtetxtexttext$-$Buffer: X\textbackslash Y\textbackslash y\textbackslash G\textbackslash X\textbackslash H\textbackslash J\textbackslash x00$-$\\ \hline 
textetxtetxtexttext & textetxtetxtexttext$-$Information: XYZ\textbackslash x00 ???\\ \hline   
\caption{calls}
\label{tab:alls}% 
\end{longtabu}

Any help is appreciated. Using packages tabu, booktabs and longtable. Thanks

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can add struts to the beginning and end of your columns as follows:

\documentclass{article}
\usepackage{tabu}
\usepackage{longtable}
\pagestyle{empty}
\newcommand{\aefrontstrut}{\rule{0pt}{0.8\baselineskip}}
\newcommand{\aebackstrut}{\rule[-0.6\baselineskip]{0pt}{0.8\baselineskip}}
\begin{document}

\begin{longtabu} to \linewidth {| m{0.41\textwidth} | >{\aefrontstrut}m{0.53\textwidth}<{\aebackstrut} |}
\hline
\multicolumn{1}{|c}{Static (stuff)} & \multicolumn{1}{|c|}{Dynamic (stuff)} \\ \hline
\endhead
\hline
\endfoot
\endlastfoot 
textetxtetxtexttext & textetxtetxtexttext$-$Buffer: X\textbackslash Y\textbackslash y\textbackslash G\textbackslash X\textbackslash H\textbackslash J\textbackslash x00$-$\\ \hline 
textetxtetxtexttext & textetxtetxtexttext$-$Information: XYZ\textbackslash x00 ???\\ \hline   
\caption{calls}
\label{tab:alls}% 
\end{longtabu}
\end{document}

You can use LaTeX's own \strut command, or you can make your own customized struts as I've done above. By using two different style struts and the > and < modifiers for columns, you can control the spacing above the first line and after the last line in that column.

enter image description here

By changing the height of the first strut and the depth of the second strut, you can finely control the spacing.

\rule[<raise>]{<width>}{<height>}

Technically, the optional argument to \rule is not the depth; it's a dimension by which the rule is raised or lowered. By using a negative value you are essentially setting the depth of the strut. Since the strut should not be visible, make sure the <width> is set to Opt.

UPDATE

As noted in the comments below, the alignment can be off if the last column contains some short text. To get around this, use the > < directives for both columns:

\begin{longtabu} to \linewidth {| >{\aefrontstrut}m{0.41\textwidth}<{\aebackstrut} | >{\aefrontstrut}m{0.53\textwidth}<{\aebackstrut} |}
share|improve this answer
    
Thanks, This almost works, but now if there is only one line in the 2nd column it is top aligned vertically not centered? –  Jerome Aug 18 '13 at 16:06
    
Add the directives to all the columns. I'll update my answer to reflect this. –  A.Ellett Aug 18 '13 at 16:12
2  
The parameter \baselineskip sometimes gets messed with by authors who need to change the line spacing of their documents. (I know, they really shouldn't be affecting the line space by modifying \baselineskip, but enough people seem to do it anyway to make this a problem to be reckoned with.) To increase the generality/robustness of your answer, you may want to express the heights and depths of the struts as multiples of a font-related parameter such as ex rather than as multiples of \baselineskip. –  Mico Aug 18 '13 at 16:23
    
@Mico Excellent point. –  A.Ellett Aug 18 '13 at 16:52
    
For another recent posting involving the use of struts to provide padding in cells of a tabular environment, see tex.stackexchange.com/a/126542/5001 (shameless self-citation alert!). –  Mico Aug 18 '13 at 17:11

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.