我怎樣才能使方程式居中或浮動?

我怎樣才能使方程式居中或浮動?

我寫了下面的等式,它看起來是左對齊的。我嘗試過\centering

\begin{center}
...
\end{center}

但還是一樣。這就是我所做的

\documentclass[12pt,letterpaper, openright]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel} 
\usepackage{amsmath, amsthm, amsfonts, bm, amssymb}
\begin{document}

\begin{center}
\begin{equation}
f(x) =
\left\{
\begin{array}{ll}
-x^{2}, &\text{if $x < 0$;}\\
\alpha + x, &\text{if $0 \leq x \leq 1$;}\\
x^{2}, &\text{otherwise.}
\end{array}
\right.
\end{equation}
\end{center}   

\end{document}

這是結果

在此輸入影像描述

答案1

即使您使用iwona淺色、簡潔的數學字體,結果也符合預期。當然,您應該刪除center方程式周圍的環境,正如其他人已經提到的:

\documentclass[12pt, letterpaper, openright]{article}
\usepackage[spanish]{babel}
\usepackage[light, condensed, math]{iwona}
\usepackage{amsmath, amssymb, amsthm, bm}

\usepackage{lipsum}

\begin{document}
\lipsum[11]
    \begin{equation}
f(x) = \begin{cases}
    -x^{2},     & \text{if $x < 0$;}\\
    \alpha + x, & \text{if $0 \leq x \leq 1$;}\\
    x^{2},      & \text{otherwise.}
       \end{cases}
    \end{equation}
\lipsum[12]
\end{document}

在此輸入影像描述

答案2

預設情況下,equation環境以方程式為中心,因此您不需要環境center。此外,array你應該使用cases環境,而不是使用。透過這兩項更改,您的 MWE 會產生:

在此輸入影像描述

這是更新後的程式碼:

\documentclass[12pt,letterpaper, openright]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath, amsthm, amsfonts, bm, amssymb}
\begin{document}

\begin{equation}
  f(x) = \begin{cases}
            -x^{2}, &\text{if $x < 0$;}\\
            \alpha + x, &\text{if $0 \leq x \leq 1$;}\\
            x^{2}, &\text{otherwise.}
          \end{cases}
\end{equation}

\end{document}

答案3

如果您願意,有一天要使用您的起始程式碼,您應該刪除,\begin{center}...\end{center}因為環境equation給出了居中公式。根據用戶@Mico的正確建議,您的螢幕截圖與程式碼不同:我看到字體是伊沃納

\documentclass[12pt,letterpaper, openright]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel} 
\usepackage{amsmath, amsthm, amsfonts, bm, amssymb}
\begin{document}


\begin{equation}
f(x) =
\left\{
\begin{array}{ll}
-x^{2}, &\text{if $x < 0$;}\\
\alpha + x, &\text{if $0 \leq x \leq 1$;}\\
x^{2}, &\text{otherwise.}
\end{array}
\right.
\end{equation}


\end{document}

在此輸入影像描述

答案4

謝謝回答。錯誤是在使用\usepackage[light, condensed, math]{iwona}我的文件序言中也有的包時出現的,但為了簡單起見,我沒有附加它。

透過從套件中刪除數學選項iwona。把它放在一邊,\usepackage[light, condensed]{iwona}我得到了問題的解決方案。

相關內容