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:
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.
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} |}
Best Answer