如何定義 flalign 環境的寬度?

如何定義 flalign 環境的寬度?

我試圖讓 flalign 環境中的方程式與其上方表格環境中的文字左對齊,並具有相同的寬度 - 0.8\textwidth。該方程式是一個約束,理想情況下它的間距與上面的參數線相似,但我只是不知道如何使其工作。我嘗試過使用小型頁面,並且還嘗試將方程式放入表格環境中。

現在看起來怎麼樣

這就是它目前的樣子,我希望以“wqq_t”開頭的方程式包含在與上面的表格環境相同的寬度內。

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{tabular}{lp{0.8\textwidth}}
    & \\
    \multicolumn{2}{l}{\textbf{Sets and Parameters}} \\
    $\mathcal{B}$ & Description of this parameter\\
    \\
    \multicolumn{2}{l}{\textbf{Objective and Constraints}} 
\end{tabular}

\begin{minipage}{0.8\textwidth}
    \begin{flalign}
        &\wqq_t = k && \forall t \in \mathcal{B} \label{eq: br1}
    \end{flalign}
\end{minipage}

\end{document}

答案1

最大的問題是你想要匹配表格的內部還是外部。對於外部,只需測量表格的寬度即可。對於內部,您需要考慮\tabcolsep並 在本例中\arrayrulewidth由表格自動新增。

\documentclass{article}
\usepackage{amsmath}

\newsavebox{\tempbox}

\begin{document}
\savebox\tempbox{% measure width
\begin{tabular}{|lp{0.8\textwidth}|}
    & \\
    \multicolumn{2}{|l|}{\textbf{Sets and Parameters}}  \\
    $\mathcal{B}$ & Description of this parameter\\
    &\\
    \multicolumn{2}{|l|}{\textbf{Objective and Constraints}} 
\end{tabular}}\usebox\tempbox

\begin{minipage}{\wd\tempbox}% match exterior
    \begin{flalign}
        &wqq_t = k && \forall t \in \mathcal{B} \label{eq: br1}
    \end{flalign}
\end{minipage}

\hspace*{\dimexpr \tabcolsep+\arrayrulewidth}%
\begin{minipage}{\dimexpr \wd\tempbox-2\tabcolsep-2\arrayrulewidth}
    \begin{flalign}
        &wqq_t = k && \forall t \in \mathcal{B} \label{eq: br1}
    \end{flalign}
\end{minipage}

\end{document}

示範

相關內容