0

I know that I must not use vertical rules but I'm trying to reproduce a SAS output like this:

enter image description here

When I use a simple tabular my code works well (see the first table below), but when I use one or more X column from tabularx some undesired vertical space appears (see the 2nd and the 3rd tables below).

What am I doing wrong?

\documentclass{book} 
\usepackage{array}
\usepackage{tabularx}
\renewcommand*{\arraystretch}{1.1}
\usepackage{tcolorbox}
\newcommand{\stilecomandoa}{\color{blue!60!black}\bfseries}

\begin{document} 
    \begin{center}
        \begin{tabular}{|>{\stilecomandoa}r|l|l|r|}
            \hline
            \multicolumn{4}{|c|}{\stilecomandoa Alphabetic List of Variables and Attributes}\\      
            \hline
            \# & {\stilecomandoa Variable} & {\stilecomandoa Type} & {\stilecomandoa Len} \\
            \hline
            3 & Age & Num & 8 \\
            \hline
            4 & Height & Num & 8 \\
            \hline
            1 & Name & Char & 8 \\
            \hline
            2 & Sex & Char & 1 \\
            \hline
            5 & Weight & Num & 8 \\
            \hline
        \end{tabular}    
    \end{center}
    \begin{center}
        \begin{tabularx}{.7\linewidth}{|>{\stilecomandoa\arraybackslash}X|X|X|X|}
            \hline
            \multicolumn{4}{|c|}{\stilecomandoa Alphabetic List of Variables and Attributes}\\      
            \hline
            \# & {\stilecomandoa Variable} & {\stilecomandoa Type} & {\stilecomandoa Len} \\
            \hline
            3 & Age & Num & 8 \\
            \hline
            4 & Height & Num & 8 \\
            \hline
            1 & Name & Char & 8 \\
            \hline
            2 & Sex & Char & 1 \\
            \hline
            5 & Weight & Num & 8 \\
            \hline
        \end{tabularx}
    \end{center}
    \begin{center}
        \begin{tabularx}{.7\linewidth}{|>{\stilecomandoa\arraybackslash}r|X|X|r|}
            \hline
            \multicolumn{4}{|c|}{\stilecomandoa Alphabetic List of Variables and Attributes}\\      
            \hline
            \# & {\stilecomandoa Variable} & {\stilecomandoa Type} & {\stilecomandoa Len} \\
            \hline
            3 & Age & Num & 8 \\
            \hline
            4 & Height & Num & 8 \\
            \hline
            1 & Name & Char & 8 \\
            \hline
            2 & Sex & Char & 1 \\
            \hline
            5 & Weight & Num & 8 \\
            \hline
        \end{tabularx}   
    \end{center}
\end{document}

enter image description here

  • 2
    it's a documented feature (use \leavevmode before \color. – David Carlisle Jan 5 '18 at 7:52
  • @DavidCarlisle Ops, I didn't read the documentation! – CarLaTeX Jan 5 '18 at 7:53
  • 1
    texdoc grfguide footnote on page 6 – David Carlisle Jan 5 '18 at 7:54
  • 1
    note it's not using tabularx that is the problem, it is changing l to p column type – David Carlisle Jan 5 '18 at 7:55

Browse other questions tagged or ask your own question.