3

I have a table (tabulary) in which some cells are only filled with a rule. This rule is 1ex thick and I want that the bottom of the rule matchs the baseline (of all cells of the row).

I've found that when I define a color for this rule, and if there is no text in the cell before the rule, the baseline of the rule-cell does not match the baseline of the other celles of the row.

MWE

Where is the dummy error I'm not finding?!


\documentclass{scrartcl}
    \usepackage{tabulary}
    \usepackage{xcolor}
\begin{document}    
    \begin{tabulary}{.5\textwidth}{|L|L|R|}
        \hline%
            foo
            &
            \rule{1cm}{1ex}
            &
            bar
        \\\hline
            foo
            &
            \rule{1cm}{1ex} bar
            &
            baz
        \\\hline
            foo
            &
            bar \rule{1cm}{1ex}
            &
            baz
        \\\hline
    \end{tabulary}

    \begin{tabulary}{.5\textwidth}{|L|L|R|}
        \hline%
        foo
        &
        {\color{black!50}\rule{1cm}{1ex}}
        &
        bar
        \\\hline
        foo
        &
        {\color{black!50}\rule{1cm}{1ex}} bar
        &
        baz
        \\\hline
        foo
        &
        bar {\color{black!50}\rule{1cm}{1ex}}
        &
        baz
        \\\hline
    \end{tabulary}
\end{document}

2 Answers 2

5

Don't use \color unless you specifically need it (which should be rare); use \textcolor, instead.

\documentclass{scrartcl}
\usepackage{tabulary}
\usepackage{xcolor}

\begin{document}    

\begin{tabulary}{.5\textwidth}{|L|L|R|}
\hline
foo & \rule{1cm}{1ex}     & bar \\
\hline
foo & \rule{1cm}{1ex} bar & baz \\
\hline
foo & bar \rule{1cm}{1ex} & baz \\
\hline
\end{tabulary}

\begin{tabulary}{.5\textwidth}{|L|L|R|}
\hline
foo & \textcolor{black!50}{\rule{1cm}{1ex}}     & bar \\
\hline
foo & \textcolor{black!50}{\rule{1cm}{1ex}} bar & baz \\
\hline
foo & bar \textcolor{black!50}{\rule{1cm}{1ex}} & baz \\
\hline
\end{tabulary}
\end{document}

enter image description here

The problem is that \color{...} inserts a whatsit (a special node in the list to typeset) that doesn't start paragraph mode. So the paragraph starts with \rule and the whatsit ends up in a line by itself.

2

A workaound: add >{\mbox{}} (or >{\leavevmode} in the preamnle of the table for the relevant columns:

\documentclass{scrartcl}
    \usepackage{tabulary}
    \usepackage{xcolor}
\begin{document}
    \begin{tabulary}{.5\textwidth}{|L|L|R|}
        \hline%
            foo
            &
            \rule{1cm}{1ex}
            &
            bar
        \\\hline
            foo
            &
            \rule{1cm}{1ex} bar
            &
            baz
        \\\hline
            foo
            &
            bar \rule{1cm}{1ex}
            &
            baz
        \\\hline
    \end{tabulary}

    \begin{tabulary}{.5\textwidth}{|L| >{\mbox{}}L|R|}
        \hline%
        foo
        &
        \color{black!50}\rule{1cm}{1ex}
        &
        bar
        \\\hline
        foo
        &
    {\color{black!50}\rule{1cm}{1ex}} bar
        &
        baz
        \\\hline
        foo
        &
        bar {\color{black!50}\rule{1cm}{1ex}}
        &
        baz
        \\\hline
    \end{tabulary}
\end{document} 

enter image description here

2
  • Great! Do you know the theory behind this workaround?
    – ebosi
    Apr 14, 2016 at 9:30
  • Not at all. I don't know the internals of tabulary. I just observed from your example that, if the rule comes after some text, there's no problem. I'll try to see if it happens also with, say, tabularx.
    – Bernard
    Apr 14, 2016 at 9:45

You must log in to answer this question.

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