8

I use tabu to easily specify colors for different parts of my table. Also the X column makes life easier. I have some problems regarding vertical placement:

In the linked figure you can see many defects:

enter image description here

  1. First Row: Text not vertically-aligned
  2. Multiple line in the last column is not well placed. Although single line is good (Operand A)
  3. Item lists have no space above, and plenty below!

If I replaced the "X[8,m]" from the fourth column to "X[8,l]", problem 2 and 3 are fixed. But this breaks the middle alignment of the first three columns to top.

What am I missing?

\documentclass{article}
\usepackage{tabu}
\usepackage{xcolor,colortbl}
\usepackage{enumitem}

\begin{document}

Test this

\vspace*{1cm}

\tabulinestyle{1pt blue}
\begin{tabu}[m]{
     |[1pt blue] X[2.2,m]
     |[1pt gray] X[m]
     |[1pt gray] X[m]
     |[1pt gray] X[8,m]
     |[1pt blue] } \everyrow{\tabucline[1pt gray]-}

\rowfont[C]{\bf\large\color{white}} \rowcolor{blue} Port & Width & Type & Description \\

OperandA & Mode & Input & 
Operand A  \\ 

OperandB & Mode & Input & 
Operand B in IEEE format and some constraints \\ 

Mode & 3 & Input & 
\begin{itemize}[nolistsep,noitemsep,leftmargin=1em]
    \item 000 Round to  
    \item 001 Round away 
    \item 010 Round toward 
    \item 011 Round toward minus 
    \item 100 Round Toward
    \item 101 Round to nearest 
    \item 110 Round to nearest 
    \item 111 Reserved 
\end{itemize} \\

Precision & 1 & Input  &
\begin{itemize}[nolistsep,noitemsep,leftmargin=1em]
    \item 1 Enable 64 operand
    \item 0 Enable 128 operand
\end{itemize} \\

Oper & 1 & Input & \textit{Operation selector}:
\begin{itemize}[nolistsep,noitemsep,leftmargin=1em]
    \item 100 bla
    \item 101 blaaa
    \item 000 
    \item 110 
    \item 111 
    \item 001 
    \item 010 
    \item 011 
\end{itemize} \\

Condition & 5 & Input & 
\textit{Comparison condition selector}: 
The valid combination are seen in standard-defined Comparisons \\ 

\multicolumn{4}{|c|}{Clock, Reset, and Enable are relevant only to pipelined designs} \\ 

Clock & 1 & Input & System Clock (relevant only to pipelined designs) \\
Reset & 1 & Input & System Asynchronous Reset, active low \\

Enable & 1 & Input & \textit{System Enable}. When Enable = 0, the Clock and Reset inputs are held \\ \tabucline[1pt blue]-\end{tabu}

\end{document}
8

The spacing
tabu, as most other table packages, has some problem with spacing, especially when you are using list-environments. Therefore, we all longing for v 2.9. Try using \tabulinesep=1.3mm and remove the nolistsep from the two first listings (or give topsep= a small value (f.ex. 0.1ex). After \textit{Operation selector} put a \newline. Listings in tables are challenging.

I have tinkered a bit more with your code. The bad spacing around lists are not tabu’s fault, but the itemize-environment adding, in this setting, unnecessary space. I solved this by including the itemize-environment in a 5 cm wide \parbox and reducing the topsep to 0.1ex. If you have necessary skills, you may read the width of the fourth column from the .aux-file.

The problem with the heading is your setting of column 2 and 3. It is too narrow. I increased the width of these columns and the headings lined up. As @hakaze point out, only the last column need to be a X column; the cells in the three first columns are only one line. Use ordinary l- and c-columns instead, and the headings line up nicely.

I also added a \strut to the first column, giving the heading more depth.

Complicated table is difficult, and you have to be prepared for fine tuning whatever package you are using.

Here is the code for a new MWE:

\documentclass{article}
\usepackage{tabu}
\usepackage{xcolor,colortbl}
\usepackage{enumitem}
\usepackage[overload]{ragged2e}

\begin{document}

\tabulinesep=3pt
\tabulinestyle{1pt blue}
\begin{tabu}[m]{
     |[1pt blue] l    % or X[2.5,m]
     |[1pt gray] c    % or X[2mc]
     |[1pt gray] l    % or X[2m]
     |[1pt gray] X[8,lm]  % I suggest you set the column ragged right
     |[1pt blue] } \everyrow{\extrarowsep=^2pt\tabucline[1pt gray]-}

\rowfont[C]{\bf\large\color{white}} \rowcolor{blue} \strut Port &  Width & Type & Description  \\

OperandA & Mode & Input & 
Operand A  \\ 

OperandB & Mode & Input & 
Operand B in IEEE format and some constraints \\ 

Mode & 3 & Input & 
\parbox{5cm}{\begin{itemize}[topsep=0.1ex,noitemsep,leftmargin=1em]
    \item 000 Round to  
    \item 001 Round away 
    \item 010 Round toward 
    \item 011 Round toward minus 
    \item 100 Round Toward
    \item 101 Round to nearest 
    \item 110 Round to nearest 
    \item 111 Reserved 
\end{itemize}}
\\ 

Precision & 1 & Input  &
\parbox{5cm}{\begin{itemize}[topsep=0.1ex,noitemsep,leftmargin=1em]
    \item 1 Enable 64 operand
    \item 0 Enable 128 operand
\end{itemize}} \\

Oper & 1 & Input & \textit{Operation selector}:\newline
\parbox{5cm}{\begin{itemize}[topsep=0.1ex,noitemsep,leftmargin=1em]
    \item 100 bla
    \item 101 blaaa
    \item 000 
    \item 110 
    \item 111 
    \item 001 
    \item 010 
    \item 011 
\end{itemize}} \\

Condition & 5 & Input & 
\textit{Comparison condition selector}: 
The valid combination are seen in standard-defined Comparisons \\ 

\multicolumn{4}{|c|}{Clock, Reset, and Enable are relevant only to pipelined designs} \\ 

Clock & 1 & Input & System Clock (relevant only to pipelined designs) \\
Reset & 1 & Input & System Asynchronous Reset, active low \\

Enable & 1 & Input & \textit{System Enable}. When Enable = 0, the Clock and Reset inputs are held \\ \tabucline[1pt blue]-\end{tabu}

\end{document}

The output:

And here is the new output

  • 2
    The table head can be fixed be fixed by using the following column layout: l c c X[m] (I left out the vertical lines for legibility). – hakaze Aug 13 '12 at 12:39
  • i cant reproduce your table(it is empty). probably because i have installed recent version of the packagearray to which tabu is not compatible. – Zarko Jun 29 '18 at 8:39
  • @Zarko tabu was a promising package, but the author stopped the development, so I have not used it for several years. If you have more information regarding the incompatibility, I can add a warning in the answer. But the different tweeks to have better spacing, also work for longtable, tabularx and friends. – Sveinung Jun 29 '18 at 10:14
  • about recent troubled with tabu was discussed here on site. other packages doesn't offer possibilities for so fancy table design, however, with tabularx and makecell or cellspace is possible design nice (but less coloreful) tables. i will provide an example asap. – Zarko Jun 29 '18 at 10:29
2
  • i would not use tabu. it is not maintained, and not compatible with recent changes in array which can cause unexpected problems
  • with booktabbs, cellspace and tabularx you can design nice, more professional look table. well a bit less fancy colored (what i consider as an advantage).

enter image description here

edit: i remove local settings of the itemize lists and simplify column definitions. let me noted, that use cellspace in X column interact with vertical spaces around itemize.

\documentclass{article}
\usepackage[overload]{ragged2e}
\usepackage{booktabs, cellspace, tabularx}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{X}

\usepackage[table]{xcolor}
\usepackage{enumitem}


\begin{document}

\begin{table}[htb]
    \setlist[itemize]{nosep,label=$\bullet$,before=\vspace{-0.5\baselineskip}}

\begin{tabularx}{\linewidth}{l c l
             >{\RaggedRight} S{X}
                             }
    \hline
    \rowcolor{blue!30}
\textbf{Port} &  \textbf{Width} & \textbf{Type} & \textbf{Description}      \\
    \hline
OperandA    & Mode      & Input & Operand A                                 \\
    \midrule
OperandB    & Mode      & Input & Operand B in IEEE format
                                  and some constraints                      \\
    \midrule
Mode        & 3         & Input & \begin{itemize}
                                    \item 000 Round to
                                    \item 001 Round away
                                    \item 010 Round toward
                                    \item 011 Round toward minus
                                    \item 100 Round Toward
                                    \item 101 Round to nearest
                                    \item 110 Round to nearest
                                    \item 111 Reserved
                                  \end{itemize}         \\
    \midrule
Precision   & 1         & Input  & \begin{itemize}
                                    \item 1 Enable 64 operand
                                    \item 0 Enable 128 operand
                                   \end{itemize}        \\
    \midrule
Oper        & 1         & Input & \textit{Operation selector}:

                                  \medskip
                                  \begin{itemize}
                                    \item 100 bla
                                    \item 101 blaaa
                                    \item 000
                                    \item 110
                                    \item 111
                                    \item 001
                                    \item 010
                                    \item 011
                                  \end{itemize}     \\
    \midrule
Condition   & 5         & Input & \textit{Comparison condition selector}:
                                  The valid combination are seen in standard-defined Comparisons \\
    \midrule
\multicolumn{4}{l}{Clock, Reset, and Enable are relevant only to pipelined designs} \\
    \midrule
Clock       & 1         & Input & System Clock (relevant only to pipelined designs) \\
Reset       & 1         & Input & System Asynchronous Reset, active low \\

Enable & 1 & Input & \textit{System Enable}. When Enable = 0, the Clock and Reset inputs are held \\
    \bottomrule
\end{tabularx}
\end{table}
\end{document}
  • Addition benefit, much simpler code! – Sveinung Jul 1 '18 at 21:38
  • @Sveinung, thnak you very much! now i notice, that code example was not the last, which i tested :-(. now i remove all superfluous code chunks. – Zarko Jul 2 '18 at 3:11
  • Then even better! cellspace is obviously a package I have to use more. – Sveinung Jul 2 '18 at 7:55
  • Could you please explain to me the meaning of column type “S{X}”? – Diaa May 1 at 13:51
  • 1
    @Diaa, the setcell package define S specifier, which ad to column additional vertical space above and below cells' contents. so, S{X} is column type wo thoch cells is added space defined by \setlength\cellspacetoplimit{5pt} \setlength\cellspacebottomlimit{5pt}. if you use the siunitx package, than instead S you should use C. more details are in the package documentation. – Zarko May 1 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.