單元格之間的垂直線

單元格之間的垂直線

有人可以幫我解決如何透過完成單元格之間的垂直線來解決這個問題嗎?

問候

在此輸入影像描述

\begin{table}[htbp]
%\setlength\extrarowheight{3pt}
\renewcommand{\arraystretch}{1.2}
  \centering
  \caption{\textsc{Discrete Probability Distribution of Wind and Solar Resources, and Load}}
    \begin{tabular}{cc | cc | cc}
 \hlinewd{1.5pt}
\rowcolor[gray]{.9} \multicolumn{2}{c | }{\textbf{Solar}} & \multicolumn{2}{| c | }{\textbf{Wind }} & \multicolumn{2}{c}{\textbf{Load}} \\
 \hlinewd{1.5pt}
    \% of deviation      & Probability  & \% of deviation          & Probability     & \% of deviation           & Probability \\
        $e_{PV}$ & $\rho_{PV}$  &  $e_{W}$ &   $\rho_{W}$    &  $e_{L}$     & $\rho_{L}$ \\
 \hlinewd{1.5pt}
    -2.5 & 0.2 & -5    & 0.05 & -5    & 0.05 \\
         0 & 0.6 & -2.5 & 0.1   & -2.5 & 0.15 \\
      2.5 & 0.2 & 0      & 0.7   & 0      & 0.6 \\
         - & -    & 2.5    & 0.1   & 2.5  & 0.15 \\
          - & -    & 5      & 0.05 & 5     & 0.05 \\
 \hlinewd{1.5pt}
    \end{tabular}%
  \label{tab4.1}%
\end{table}%

答案1

這是遵循以下準則的嘗試booktabs用於專業桌子和siunitx用於對齊數值資料。

請注意,大括號 ( {...}) 用於轉義不包含要對齊的數字的單元格的內容。\multicolumn也為這些細胞提供這個目的。

在對齊中為減號留出空間是個人喜好的問題。我沒有為其留出空間(table-format=1.2表示小數點分隔符號前面有一位數字,小數點分隔符號後面有兩位數字的數字),但是您可以使用 為其留出空間table-format=-1.1

我還曾經透過在序言中重複多次*{<num-repeat>}{<col-spec>}來避免重複。<col-spec> <num-repeat>tabular

\documentclass{article}
\usepackage{booktabs,siunitx}

\begin{document}
\begin{tabular}{
  *{2}{S[table-format=1.1]} 
  *{2}{S[table-format=1.1]S[table-format=1.2]}
}
  \toprule
  \multicolumn{2}{c}{Solar} & \multicolumn{2}{c}{Wind} & \multicolumn{2}{c}{Load} \\
  \cmidrule(lr){1-2}          \cmidrule(lr){3-4}         \cmidrule(lr){5-6}
  {\% of deviation} & {Probability} & 
    {\% of deviation} & {Probability} & 
    {\% of deviation} & {Probability} \\
  {$e_{PV}$} & {$\rho_{PV}$} & 
    {$e_{W}$} & {$\rho_{W}$} & 
    {$e_{L}$} & {$\rho_{L}$} \\
  \midrule
   -2.5 &   0.2 & -5.0 & 0.05 & -5.0 & 0.05 \\
    0.0 &   0.6 & -2.5 & 0.10 & -2.5 & 0.15 \\
    2.5 &   0.2 &  0.0 & 0.70 &  0.0 & 0.60 \\
  {---} & {---} &  2.5 & 0.10 &  2.5 & 0.15 \\
  {---} & {---} &  5.0 & 0.05 &  5.0 & 0.05 \\
  \bottomrule
\end{tabular}
\end{document}

在此輸入影像描述

表格對於標準類別來說太寬article,但我不知道您正在使用什麼類別或邊距設定。如果您提供該信息,我可以提供更多幫助。

答案2

如果您確實想使用與水平規則相容的垂直規則,您應該嘗試{NiceTabular}nicematrix在那種環境中,垂直規則也與---的規則相容,儘管這根本不符合使用垂直規則booktabs的精神)booktabs

 \documentclass{article}
 \usepackage{xcolor}
 \usepackage{nicematrix}
 \usepackage{geometry}

 \makeatletter
 \def\hlinewd#1{%
 \noalign{\ifnum0=`}\fi\hrule \@height #1 %
 \futurelet\reserved@a\@xhline} 
 \makeatother

 \begin{document}

 \begin{table}[htbp]
 \renewcommand{\arraystretch}{1.2}
 \centering
 \caption{\textsc{Discrete Probability Distribution of Wind and Solar Resources, and Load}}
 \begin{NiceTabular}{cc | cc | cc}[colortbl-like]
 \hlinewd{1.5pt}
 \RowStyle{\bfseries}
 \rowcolor[gray]{.9} \Block{1-2}{Solar} && \Block{1-2}{Wind} && \Block{1-2}{Load} \\
 \hlinewd{1.5pt}
 \% of deviation & Probability & \% of deviation & Probability & \% of deviation & Probability \\
 $e_{PV}$ & $\rho_{PV}$  &  $e_{W}$ &   $\rho_{W}$    &  $e_{L}$     & $\rho_{L}$ \\
 \hlinewd{1.5pt}
 -2.5  & 0.2  & -5   & 0.05 & -5   & 0.05 \\
     0 & 0.6  & -2.5 & 0.1  & -2.5 & 0.15 \\
   2.5 & 0.2  & 0    & 0.7  & 0    & 0.6 \\
     - & -    & 2.5  & 0.1  & 2.5  & 0.15 \\
     - & -    & 5    & 0.05 & 5    & 0.05 \\
 \hlinewd{1.5pt}
 \end{NiceTabular}
 \label{tab4.1}
 \end{table}
     
 \end{document}

您需要多次編譯(因為nicematrix在背景使用 PGF/Tikz 節點)。

上述程式碼的輸出

答案3

考慮在第一行之前添加一個虛擬行:

\begin{tabular}{cc|cc|cc}
\hlinewd{1.5pt}
\rowcolor[gray]{.9} & & & & & \\[-10pt]
\rowcolor[gray]{.9}\multicolumn{2}{c|}{\textbf{Solar}} & \multicolumn{2}{|c|}
{\textbf{Wind}} & \multicolumn{2}{c}{\textbf{Load}} \\
\hlinewd{1.5pt}

可以[-10pt]根據您的口味進行調整。告訴我是否有效。

相關內容