禁忌表存在许多垂直对齐问题

禁忌表存在许多垂直对齐问题

我使用 tabu 轻松指定表格不同部分的颜色。X 列也让生活变得更轻松。我在垂直放置方面遇到了一些问题:

在里面链接图中你可以看到很多缺陷:

在此处输入图片描述

  1. 第一行:文本未垂直对齐
  2. 最后一列中的多行位置不太好。虽然单行很好(操作数 A)
  3. 物品列表上方没有空间,而下方却有很多空间!

如果我将第四列的“X[8,m]”替换为“X[8,l]”,问题 2 和 3 就解决了。但这会破坏前三列的中间对齐。

我错过了什么?

\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}

答案1

间距
tabu与大多数其他表格包一样,在间距方面存在一些问题,尤其是在使用list-environments 时。因此,我们都渴望 v 2.9。尝试使用并从前两个列表中\tabulinesep=1.3mm删除(或给出一个较小的值(例如 0.1ex)。之后放一个。表格中的列表具有挑战性。nolistseptopsep=\textit{Operation selector}\newline

我对您的代码进行了一些修改。列表周围的间距不好不是tabu的错,而是itemize-environment 在此设置中添加了不必要的空间。我通过将 -environment 包含itemize在 5 厘米宽中\parbox并将 减小到topsep0.1ex 来解决这个问题。如果您具备必要的技能,您可以从 -file 中读取第四列的宽度.aux

标题的问题在于您对第 2 列和第 3 列的设置。它太窄了。我增加了这些列的宽度,标题就对齐了。正如 @hakaze 指出的那样,只有最后一列才需要是一X列;前三列中的单元格只有一行。改用普通的l- 和c- 列,标题就可以很好地对齐了。

我还在\strut第一列添加了一个,使标题更有深度。

复杂的表格很难,并且无论使用什么包,您都必须做好微调的准备。

以下是新 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}

输出:

这是新的输出

答案2

  • 我不会使用它tabu。它没有维护,并且与最近的更改不兼容,这array可能会导致意外问题
  • 有了booktabbscellspacetabularx就可以设计出漂亮、更专业的表格。颜色不要太花哨(我认为这是优点)。

在此处输入图片描述

编辑: 我删除了列表的本地设置itemize并简化了列定义。请注意,列cellspace中的使用X与周围的垂直空间交互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}

相关内容