![セル間の縦線](https://rvso.com/image/309845/%E3%82%BB%E3%83%AB%E9%96%93%E3%81%AE%E7%B8%A6%E7%B7%9A.png)
セル間の垂直線を完成させることでこの問題を解決する方法を誰か親切に教えてくれませんか。
よろしく
\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]
好みに合わせて調整できます。うまくいったかどうか教えてください。