![關於 \multicolumn 使用的問題](https://rvso.com/image/330739/%E9%97%9C%E6%96%BC%20%5Cmulticolumn%20%E4%BD%BF%E7%94%A8%E7%9A%84%E5%95%8F%E9%A1%8C.png)
我的問題可能很簡單,但我不知道如何解決。我有兩個要合併的 stata 表(我對乳膠使用 stata 選項)。我想在我的新表格上新增標題。因此,我明白我需要使用 \multicolumn 但我嘗試了不同的方法,但似乎沒有任何效果。
{
\def\onepc{$^{\ast\ast}$} \def\fivepc{$^{\ast}$}
\def\tenpc{$^{\dag}$}
\def\legend{\multicolumn{4}{l}{\footnotesize{Significance levels
:\hspace{1em} $\dag$ : 10\% \hspace{1em}
$\ast$ : 5\% \hspace{1em} $\ast\ast$ : 1\% \normalsize}}}
\begin{table}[H]\centering
\caption{Estimation results : regress
\label{tabresult regress}}
\begin{tabular}{l r @{} l c ||c c}\hline\hline
\multicolumn{4}{c}{\textbf{OLS regression}} & {\textbf{Probit regression}}\\
\hline
\multicolumn{1}{c}
{\textbf{Variable}}
& \multicolumn{2}{c}{\textbf{Coefficient}} & \textbf{(Std. Err.)} & {\textbf{Coefficient}} & \textbf{(Std. Err.)} \\ \hline
\hline
\end{tabular}
\end{table}
}
現在看起來是什麼樣子。我們看到這是很奇怪的、不和諧的。
我希望「OLS 迴歸」位於由第二行的 3 列(變數、係數、std err)組成的區塊的中間,然後是單獨的行,然後是「機率迴歸」位於中間bloc 由第二行的2 列(係數,std err)構成。有人可以幫我解決這個問題嗎?預先非常感謝您!
答案1
從你的 MWE 中不可能確定你想要實現什麼。根據我的猜測,我格式化了下表:
獲得它非常簡單。我希望程式碼很容易理解:
\documentclass{article}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\begin{document}
My question is probably quite simple but I do not know how to solve it. I have two stata table that I am trying to merge (I use stata options for latex). I want to add a title on my new table. I thus understood that I needed to use \verb+\multicolumn+ but I try different things and nothing seems to work.
\begin{table}[htb]\centering
\caption{Estimation results: regress}
\label{tabresult regress}
\begin{tabular}{l c c ||c c}\hline\hline
\multicolumn{3}{c||}{\textbf{OLS regression}}
& \multicolumn{2}{c}{\textbf{Probit regression}}\\
\hline
\thead{Variable}
& \thead{Coefficient}
& \thead{(Std. Err.)}
& \thead{Coefficient}
& \thead{(Std. Err.)} \\
\hline
1 & 2 & 3 & 4 & 5 \\
\hline
\end{tabular}
\end{table}
\end{document}
與您的 MWE 相比,我刪除了一個虛假列(您是否rl
喜歡在小數點處格式化數字?如果是這種情況,那麼您需要不同類型的列,這可以更好地管理數字的調整,例如S
來自siunitx
包的調整)。新增包makecell
以更簡單地設定列頭。 「Probit 回歸」現在是自己的\multicolumn{2}{c}{...}
我不關心表格設計,但我鼓勵您尋找 ˙booktabs` 包,它可以啟用“專業”表格設定。舉個例子,您需要新增至少一行表格內容。