セル間の縦線

セル間の縦線

セル間の垂直線を完成させることでこの問題を解決する方法を誰か親切に教えてくれませんか。

よろしく

ここに画像の説明を入力してください

\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は、小数点の前に 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]好みに合わせて調整できます。うまくいったかどうか教えてください。

関連情報