2

I am creating a table containing times into my LaTeX document; it is coded as follows:

\documentclass[12pt]{article}

\usepackage{array}

\begin{document}

\begin{tabular}{|b{0.2\linewidth}||
                 b{0.1\linewidth}|b{0.1\linewidth}||
                 b{0.1\linewidth}|b{0.1\linewidth}||
                 b{0.1\linewidth}|b{0.1\linewidth}|}
\hline \multicolumn{7}{|c|}{Main Heading} \\
\hline &\multicolumn{2}{c||}{Sub 1} &\multicolumn{2}{c||}{Sub2} &\multicolumn{2}{c|}{Sub 3}\\
\hline \textbf{Column 1} & \textbf{Start} &\textbf{End} & \textbf{Start} & \textbf{End} & \textbf{Start} & \textbf{End}\\
\hline xx                & 12:34.5          &xx:xx.x             &xx:xx.x               &xx:xx.x           &xx:xx.x       &xx:xx.x \\
\hline xx                & xx:xx.x          &xx:xx.x             &xx:xx.x               &xx:xx.x           &xx:xx.x       &xx:xx.x \\
\hline xx                & xx:xx.x          &xx:xx.x             &xx:xx.x               &xx:xx.x           &xx:xx.x       &xx:xx.x \\
\hline xx                & xx:xx.x          &xx:xx.x             &xx:xx.x               &xx:xx.x           &xx:xx.x       &xx:xx.x \\
\hline
\end{tabular}
\end{document}

In the table definition, I am using the array package with the b{[column width]} option to vertically align the text of the cells with the bottom of the cells. However when I compile, this table is the result:

enter image description here

This clearly is not aligned as I intended: whilst the xx:xx.x cells seem to be correct at first glance, as soon as any numbers/any other text is inserted (seen in all the other cells), it is seen that the alignment is to the top of the cell.

If anyone could explain the cause of this problem and/or suggest a solution/point me in the right direction I would be greatly appreciative; tables form quite a large part of the document I am producing, and I have struggled greatly thus far.


The only (incredibly clumsy and impractical) solution I have been able to come up with myself (with my highly limited knowledge), is to define a macro which lowers its arguments by a given amount; however this not only requires me to apply it individually to each cell, but also requires me to guess the height of the cell when telling LaTeX by how much to lower the contents. For completeness the macro is (I don't imagine it will be particularly useful in the best solution to my problem):

\renewcommand{\l}[2]{\lower #1pt \hbox{#2}}

Edit: I have seen the questions here, here, here, and many many others, and found none helpful in solving my problem (I would imagine this is because every table is very different, and the solutions given on these questions were specific, not general, therefore hard to apply).

Mico
  • 506,678
  • 1
    All cell contents are bottom-aligned. However, since none of the words and letters contain descenders, the visual appearance is misleading. – Mico Oct 23 '17 at 20:35
  • 3
    I can see nothing wrong with the alignment, if your issue is the text is too close to the \hline use \setlength\extrarowheight{2pt} or whatever padding you like. – David Carlisle Oct 23 '17 at 20:37
  • @Mico what do you mean by descenders? Like subscripts etc? – aidangallagher4 Oct 23 '17 at 20:50
  • @DavidCarlisle thanks very much, this has resolved things, feel free to type up a very brief answer so I can mark this question as resolved. – aidangallagher4 Oct 23 '17 at 20:51
  • 1
    he means replace xxxx by gggg and you'll see why there is space under the letters – David Carlisle Oct 23 '17 at 20:54
  • 1
    @aidangallagher4 - A descender is the part of a glyph that reaches below the baseline. The lowercase letters g, j, and y have descenders. (Ascenders are the parts of letters that protrude above the x-line.) – Mico Oct 23 '17 at 21:09

2 Answers2

4

You may be confused over what b ("bottom alignment") means in the present context. Since all cells contain just one row, b, m ("middle") and p ("top alignment") are actually all the same. The difference between p, m, and b will only become apparent if various cells have different numbers of rows. (Recall that p, m and b all enable automatic line wrapping.)

Rather than distract the reader with all those vertical and horizontal lines, you may want to think about giving the table a more "open" and inviting look, possibly along the following lines:

enter image description here

\documentclass[12pt]{article}
\usepackage{tabularx,booktabs}
\newcolumntype{Y}{>{\hsize=1.750\hsize}X}
\newcolumntype{Z}{>{\hsize=0.875\hsize\centering\arraybackslash}X}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{}Y*{6}{Z}@{}}
\multicolumn{7}{c}{Main Heading} \\
\midrule[\heavyrulewidth]
Column 1
&\multicolumn{2}{c}{Sub 1}   
&\multicolumn{2}{c}{Sub 2}           
&\multicolumn{2}{c@{}}{Sub 3}\\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7} 
& Start & End & Start & End & Start & End \\
\midrule
 xx     & 12:34.5 &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x \\
 xx     & xx      &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x \\
 xx     & xx      &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x \\
 xx     & xx      &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x &xx:xx.x \\
\bottomrule
\end{tabularx}
\end{document}
Mico
  • 506,678
3

I can see nothing wrong with the alignment, as there is only one row of text in the cell, b is the same as p and aligns on the baseline of the cell.

If your issue is the text is too close to the \hline use

\setlength\extrarowheight{2pt} 

or whatever padding you like.

David Carlisle
  • 757,742