對齊方程式以複製迴歸輸出

對齊方程式以複製迴歸輸出

我一直在嘗試在 LaTeX 中複製以下方程式(來自回歸輸出): 在此輸入影像描述

我嘗試過使用tabularandalign但仍然無法獲得類似的外觀。具體來說,括號中的數量正好位於係數下方、小數點對齊等等。有關如何實現它的任何線索?

編輯:我想我應該包括我作為 MWE 的嘗試:

\documentclass{article}

\usepackage{amsmath}
\newcommand{\ti}[1]{\textit{#1}}

\begin{document}

\begin{alignat*}{9}
    \widehat{\ti{math}4} & = 24.49 & {} - .274 & \ti{pctsgle} & {} - .422 & \ti{free} & {} - .752 & \ti{lmedinc} & {} + 9.01 & \ti{lexppp} \\
    & \phantom{{} = {}} (59.24) & (.161) & & (.071) & & (5.358) & & (4.04) \\
    n & = 299, R^2 = .472
\end{alignat*}

\end{document}

答案1

隨著使用array.數字表示法略有變化(小數點前方總是數字):

在此輸入影像描述

\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{mathabx}  % for widehat
\newcommand{\ti}[1]{\textit{#1}}

\usepackage{siunitx}

\begin{document}
    \[\setlength\arraycolsep{2pt}
      \sisetup{input-symbols = {( )}}
\begin{array}{r c
                S[table-format=2.2]  c
                S[table-format=1.3]l c
                S[table-format=1.3]l c
                S[table-format=1.3]l c
                S[table-format=1.2]l 
              }  
\widehat{\ti{math}4} 
    & = 
    & 24.49 & - & 0.274   & \ti{pctsgle} & - 
                & 0.422   & \ti{free}    & - 
                & 0.752   & \ti{lmedinc} & + 
                & 9.01    & \ti{lexppp}   \\
    &
    & (59.24) & & (0.161) & &
                & (0.071) & &
                & (5.358) & &
                & (4.04)  &               \\
n   & = &  \multicolumn{13}{l}{299,\quad R^2 = 0.472}
\end{array}
    \]
\end{document}

答案2

我會將底部的數字列印得較小,因此它們不太可能與較接近的數字歸類。我們\hidewidth確保它們不佔用水平空間,但無論如何都在主係數下方居中。

\documentclass{article}
\usepackage{amsmath,amssymb}

\newcommand{\tvar}[1]{\operatorname{\mathit{#1}}}
\newcommand{\coeff}[2]{%
  \begingroup\renewcommand{\arraystretch}{0.75}%
  \begin{array}[t]{@{}c@{}}
    #1 \\ % the main number
    \scriptstyle \hidewidth(#2)\hidewidth
  \end{array}%
  \endgroup
}

\begin{document}

\begin{align*}
\widehat{\tvar{math}4} 
& = \coeff{24.49}{59.24}
  - \coeff{.274}{.161} \tvar{pctsgle}
  - \coeff{.422}{.071} \tvar{free} 
  - \coeff{.752}{5.538} \tvar{lmedinc}
  + \coeff{9.01}{4.04} \tvar{lexppp}
\\
n & = 299,\quad R^2 = .472
\end{align*}

\end{document}

在此輸入影像描述

相關內容