如何使用 booktabs 套件建立表格?

如何使用 booktabs 套件建立表格?

我想使用 booktabs 套件建立下表,但我不太確定該怎麼做

在此輸入影像描述

在此輸入影像描述

任何幫助是極大的讚賞!

答案1

calstable 和 tabularx 表

這是您的兩個表格排版為calstables,IE。使用該包卡路里。我還使用排版了第一個表表格x,網路,大批多行。我用了表格x,因為該套件可以考慮所有必要的變數來計算列寬。

可調節的

calstable不支援雙規則(雙邊框),因此我使用窄行和列偽造了此類規則。

由於我在同一文件中排版了兩個表格,因此我將表格設定命令和定義從表格序言的捷徑移至文件序言。我已經調整了所有規則(行),確保沒有任何單一規則會切割雙雙規則。因此,您將看到在多個位置使用的快捷方式\lb\rb用於關閉單一儲存格的刪除和開啟規則。雙垂直規則如何連接到雙水平規則取決於當地的印刷傳統,因此我不保證您的管轄範圍內的選擇是正確的。

我填寫了一些儲存格內容,以正確的行高排版表格,因此,我將第一個表格中的行高增加到 \baselineskips,與前面的範例相比。此外,我使用記錄的掛鉤將所有單元格中的單元格內容垂直居中,請參閱命令\def\cals@AtBeginCell{\vfil}

在此輸入影像描述

\documentclass{article}
\usepackage{cals}

% Set up the carlstable
\makeatletter
%% All rules of same weight
\def\cals@framers@width{0.3pt}   % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.3pt}
\def\cals@bodyrs@width{0.3pt}
\def\cals@cs@width{0.3pt}             % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.3pt}
\def\cals@AtBeginCell{\vfil}            % All cell contents vertically centred

% Shorthands for spanning cells, table rules and the spece between columns and rows (padding)
\let\nc=\nullcell
\let\sc=\spancontent

\def\rb{\ifx\cals@borderR\relax     % Right Border (rules) switch (off-on)
    \def\cals@borderR{0.0pt}
\else \let\cals@borderR\relax\fi}

\def\lb{\ifx\cals@borderL\relax     % Left Border switch (off-on)
    \def\cals@borderL{0.0pt}
\else \let\cals@borderL\relax\fi}

\def\bb{\ifx\cals@borderB\relax     % Bottom Border switch (off-on)
    \def\cals@borderB{0.0pt}
\else \let\cals@borderB\relax\fi}

\def\tp{\ifdim\cals@paddingT=0.0pt\relax    % Top padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingT}{0pt}\fi}

\def\bp{\ifdim\cals@paddingB=0.0pt\relax    % Bottom padding switch (off-on)
\cals@setpadding{Ag}
\else \setlength{\cals@paddingB}{0pt}\fi}
\makeatother

\begin{document}

\begin{calstable}[c]
% Defining 11 columns, 2 are for double vertical rules (col2 and col7)
\colwidths{{\dimexpr(\columnwidth/21*3)}
                   {2pt}
                   {\dimexpr(\columnwidth/21*2)}
                   {\dimexpr(\columnwidth/21*1)}
                   {\dimexpr(\columnwidth/21*2)}
                   {\dimexpr(\columnwidth/21*4)}
                   {2pt}
                   {\dimexpr(\columnwidth/21*2)}
                   {\dimexpr(\columnwidth/21*1)}
                   {\dimexpr(\columnwidth/21*2)}
                   {\dimexpr(\columnwidth/21*4)}
            }

\makeatletter
% R1H1  % This first row is just to ‘fake’ double horizontal lines
\thead{%
\brow
    \rb\tp\cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}\rb
    \cell{}\tp
    \ht\cals@current@row=2pt
\erow
%
%R2H2 % Header
\brow
    \alignC\cell{C}
    \bb\cell{}\bb
    \nc{ltb}
    \nc{tb}
    \nc{tb}
    \nc{rtb}\sc{}
    \bb\cell{}\bb
    \nc{ltb}
    \nc{tb}
    \nc{tb}
    \nc{rtb}\sc{}
\erow
}
\tfoot{\lastrule\strut}
%R3B1
\brow
    \cell{C}
    \bb\cell{}\bb
    \nc{ltb}
    \nc{rtb}\sc{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \nc{ltb}
    \nc{rtb}\sc{}
    \cell{}
    \cell{}
\erow
%R4B2
\brow
    \nc{lrt}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \ht\cals@current@row=2\normalbaselineskip
\erow
%R5B3
\brow
    \nc{lrb}\alignC\sc{C}
    \bb\cell{}\bb
    \cell{C}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R6B4
\brow
    \nc{lrt}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \ht\cals@current@row=2\normalbaselineskip
\erow
%R7B5
\brow
    \nc{lrb}\alignC\sc{C}
    \bb\cell{}\bb
    \cell{C}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R8B6
\brow
    \nc{lrt}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \ht\cals@current@row=2\normalbaselineskip
\erow
%R9B7
\brow
    \nc{lrb}\alignC\sc{C}
    \bb\cell{}\bb
    \cell{C}
    \cell{}
    \cell{}
    \cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R10B9  % This last row is just to ‘fake’ double horizontal lines
\brow
    \rb\bp\cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
    \cell{}\rb
    \cell{}\bp
    \ht\cals@current@row=2pt
\erow
\makeatletter
\end{calstable}\par

\vspace{1cm}

\begin{calstable}[l]
% Defining 5 columns, 1 are for double vertical rules (col2)
\colwidths{{\dimexpr(\columnwidth/15*3)}
                   {2pt}
                   {\dimexpr(\columnwidth/15*2)}
                   {\dimexpr(\columnwidth/15*1)}
                   {\dimexpr(\columnwidth/15*3)}
            }

\makeatletter
% R1H1  % This first row is just to ‘fake’ double horizontal lines
\thead{%
\brow
    \rb\tp\cell{}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}\rb\tp
    \ht\cals@current@row=2pt
\erow
%
%R2H2 % Header
\brow
    \alignC\cell{C}
    \bb\cell{}\bb
    \cell{}
    \cell{}
    \cell{}
\erow
}
\tfoot{\lastrule\strut}
%R4B2
\brow
    \bb\cell{C}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R5B3
\brow
    \cell{C}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R6B4
\brow
    \cell{C}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R7B5
\brow
    \cell{C}
    \cell{}
    \cell{}
    \cell{}
    \cell{}
\erow
%R8B6
\brow
    \bb\cell{C}\bb
    \cell{}
    \bb\cell{}
    \cell{}
    \cell{}\bb
\erow
%R10B9  % This last row is just to ‘fake’ double horizontal lines
\brow
    \bb\rb\bp\cell{}
    \cell{}
    \cell{}
    \cell{}\rb
    \cell{}\bb
    \ht\cals@current@row=2pt
\erow
\makeatletter
\end{calstable}\par
\end{document}

表格和朋友們

這是您的第一個表格排版表格x和朋友。正如您將看到的,列和列寬的設定和定義非常複雜。為了獲得正確的連接規則,我使用了網路包裹。

在此輸入影像描述

\documentclass{article}
\usepackage{array, tabularx, multirow, hhline}

% Two shorthands to secured equal rowheigth 
\newcommand*{\hz}{\vphantom{\parbox[c]{1cm}{\rule{1cm}{1.5\normalbaselineskip}}}}
\newcommand*{\vz}{\vphantom{\parbox[c]{1cm}{\rule{1cm}{2.5\normalbaselineskip}}}}

% Define four new X column types based on width. tabularx takes care of the maths involved
\newcolumntype{A}{>{\centering\arraybackslash\hsize=0.4\hsize\linewidth=\hsize}X}
\newcolumntype{B}{>{\centering\arraybackslash\hsize=0.3\hsize\linewidth=\hsize}X}
\newcolumntype{C}{>{\centering\arraybackslash\hsize=0.2\hsize\linewidth=\hsize}X}
\newcolumntype{D}{>{\centering\arraybackslash\hsize=0.1\hsize\linewidth=\hsize}X}

% Uncomment to see margins etc.
%\usepackage{showframe}
%\renewcommand*\ShowFrameColor{\color{red}}
%\renewcommand*\ShowFrameLinethickness{.15pt}

\setlength{\tabcolsep}{0.5em}
\setlength{\extrarowheight}{4pt} % Push first line of text away from rules above.

\begin{document}

\centering
\begin{tabularx}{\linewidth}{|B||C|D|C|A||C|D|C|A|}

\hhline{|*{9}{=}|}
\hz B   &    \multicolumn{4}{c||}{}   &  \multicolumn{4}{c|}{}\\
\hhline{|-||----||----|}
\hz B   &    \multicolumn{2}{c|}{}   &    &      &   \multicolumn{2}{c|}{} &   & \\
\hhline{|-||--|-|-||--|-|-|}
\vz\multirow[c]{3}{=}{\centering B}     &       &      &    &      &    &   &   & \\
\hhline{|~||--|-|-||--|-|-|}
\hz     &    C  &      &    &      &    &   &   & \\
\hhline{|-||--|-|-||--|-|-|}
\vz\multirow[c]{3}{=}{B}    &       &     &    &      &    &   &   & \\
\hhline{|~||--|-|-||--|-|-|}
\hz     &    C  &      &   &      &    &   &   & \\
\hhline{|-||--|-|-||--|-|-|}
\vz \hz\multirow[c]{3}{=}{B}    &       &      &    &      &    &   &   & \\
\hhline{|~||--|-|-||--|-|-|}
\hz     &    C  &      &    &      &    &   &   &  \\
\hhline{|*{9}{=}|}

\end{tabularx}

\end{document}

相關內容