将分数(和表达式)水平居中

将分数(和表达式)水平居中

我试图将分数居中,但它似乎相对于框的中心向上移动。以下是代码:

\documentclass[12pt]{article}
\usepackage{amssymb, graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{float}
\usepackage{enumitem}
\usepackage{amsfonts,bm}
\usepackage{diagbox}
\usepackage[makeroom]{cancel}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}
\usepackage[american,siunitx]{circuitikz}
\usepackage[export]{adjustbox}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\DeclarePairedDelimiter\norm{\lvert}{\rvert}
\usepackage{units}
\usepackage{relsize}
\usepackage[margin=1in]{geometry} 
\let\DeclareUSUnit\DeclareSIUnit
\let\US\SI
\DeclareUSUnit\mile{mi}
\usepackage{optidef}
\usepackage{interval}


\intervalconfig{
    soft open fences,
    separator symbol=, ,
} 

\begin{document}
    \title{\vspace{-2cm}HW 8}
    \author{John Doe}
    \date{\today}
    \maketitle
    \begin{enumerate}[leftmargin =*]
        \item Looking at $x$, we see that $T = 0.2\pi$, so $x = \sin\left(10t\right)$. Therefore, 
        $$\bm{\Phi}\left(t\right) = \begin{bmatrix} 1 & \sin\left(10t\right) & \sin^2\left(10t\right) & \sin^3\left(10t\right) & \sin^4\left(10t\right)\end{bmatrix}^T
        $$
        Next,
        $$\bm{\Phi}\left(t\right)\bm{\Phi}^T\left(t\right) =
        \begin{bmatrix}
            1 & \sin\left(10t\right) & \sin^2\left(10t\right) & \sin^3\left(10t\right) & \sin^4\left(10t\right)\\
            \sin\left(10t\right) & \sin^2\left(10t\right) & \sin^3\left(10t\right) & \sin^4\left(10t\right) & \sin^5\left(10t\right)\\
            \sin^2\left(10t\right) & \sin^3\left(10t\right) & \sin^4\left(10t\right) & \sin^5\left(10t\right) & \sin^6\left(10t\right)\\
            \sin^3\left(10t\right) & \sin^4\left(10t\right) & \sin^5\left(10t\right) & \sin^6\left(10t\right) & \sin^7\left(10t\right)\\
            \sin^4\left(10t\right) & \sin^5\left(10t\right) & \sin^6\left(10t\right) & \sin^7\left(10t\right) & \sin^8\left(10t\right)
        \end{bmatrix}
        $$
        Then, the PE condition is evaluated as
        $$\int_{t}^{t+T}\bm{\Phi}\left(\tau\right)\bm{\Phi}^T\left(\tau\right) d\tau=
        \int_{t}^{t+T}
        \begin{bmatrix}
            1 & \sin\left(10\tau\right) & \sin^2\left(10\tau\right) & \sin^3\left(10\tau\right) & \sin^4\left(10\tau\right)\\
            \sin\left(10\tau\right) & \sin^2\left(10\tau\right) & \sin^3\left(10\tau\right) & \sin^4\left(10\tau\right) & \sin^5\left(10\tau\right)\\
            \sin^2\left(10\tau\right) & \sin^3\left(10\tau\right) & \sin^4\left(10\tau\right) & \sin^5\left(10\tau\right) & \sin^6\left(10\tau\right)\\
            \sin^3\left(10\tau\right) & \sin^4\left(10\tau\right) & \sin^5\left(10\tau\right) & \sin^6\left(10\tau\right) & \sin^7\left(10\tau\right)\\
            \sin^4\left(10\tau\right) & \sin^5\left(10\tau\right) & \sin^6\left(10\tau\right) & \sin^7\left(10\tau\right) & \sin^8\left(10\tau\right)
        \end{bmatrix} d\tau
        $$
        We now take a look at each trig integral with different powers.
        \begin{table}[H]
            \centering
            \begin{tabular}{|c|c|}
                \hline
                $n$ & $\mathlarger{\int\sin^n\left(10\tau\right)d\tau}$\\ [12pt]
                \hline
                0 & $\tau$\\[12pt]
                \hline
                1 & $-\dfrac{\cos\left(10\tau\right)}{10}$\\[12pt]
                \hline
                2 & $\dfrac{\tau}{2} - \dfrac{\sin\left(20\tau\right)}{40}$\\[12pt]
                \hline
                3 & $\dfrac{\frac{\cos^3\left(10\tau\right)}{3} - \cos\left(10\tau\right)}{10}$\\[12pt]
                \hline
                4 & $\dfrac{120\tau - 8\sin\left(20\tau\right) + \sin\left(40\tau\right)}{320}$\\[12pt]
                \hline
                5 & $\dfrac{-\frac{\cos^5\left(10\tau\right)}{5} + \frac{2\cos^3\left(10\tau\right)}{3}- \cos\left(10\tau\right)}{10}$\\[12pt]
                \hline
                6 & $\dfrac{600\tau + 4\sin^3\left(20\tau\right) - 48\sin\left(20\tau\right) + 9\sin\left(40\tau\right)}{1920}$\\[12pt]
                \hline
                7 & $\dfrac{\frac{\cos^7\left(10\tau\right)}{7} - \frac{3\cos^5\left(10\tau\right)}{5} + \cos^3\left(10\tau\right) - \cos\left(10\tau\right)}{10}$\\[12pt]
                \hline
                8 & $\dfrac{8400\tau + 128\sin^3\left(20\tau\right) - 768\sin\left(20\tau\right) + 168\sin\left(40\tau\right) + 3\sin\left(80\tau\right)}{30720}$\\[12pt]
                \hline
            \end{tabular}
            \caption{Trig integrals for powers of $n \in [0,8] \in \mathbb{Z}$.}
        \end{table}
        Then, with $T = 0.2\pi$ and applying the integral bounds, we get the following:
        \begin{table}[H]
            \centering
            \begin{tabular}{|c|c|}
                \hline
                $n$ & $\mathlarger{\int_{t}^{t+T}\sin^n\left(10\tau\right)d\tau}$\\ [12pt]
                \hline
                0 & $0.2\pi$\\[12pt]
                \hline
                1 & $0$\\[12pt]
                \hline
                2 & $0.1\pi$\\[12pt]
                \hline
                3 & $0$\\[12pt]
                \hline
                4 & $\dfrac{3\pi}{40}$\\[12pt]
                \hline
                5 & $0$\\[12pt]
                \hline
                6 & $\dfrac{\pi}{16}$\\[12pt]
                \hline
                7 & $0$\\[12pt]
                \hline
                8 & $\dfrac{7\pi}{128}$\\[12pt]
                \hline
            \end{tabular}
        \end{table}
    \end{enumerate}
\end{document}

这是我目前得到的输出:

在此处输入图片描述

在此处输入图片描述

有没有办法让它们居中?

答案1

一揽子cellspace解决方案,其中

  • 所有[12pt]使用的内容\\[12pt]都被删除,因为这只会在表格单元格的底部添加垂直空间。
  • cellspace已加载并且两个长度已改变
\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{float}
\usepackage{relsize}

\usepackage[column=O]{cellspace}
\setlength{\cellspacetoplimit}{5pt}
\setlength{\cellspacebottomlimit}{5pt}

\begin{document}
\begin{table}[H]
  \centering
  \begin{tabular}{|Oc|Oc|}
      \hline
      $n$ & $\mathlarger{\int\sin^n\left(10\tau\right)d\tau}$\\ 
      \hline
      0 & $\tau$\\
      \hline
      1 & $-\dfrac{\cos\left(10\tau\right)}{10}$\\
      \hline
      2 & $\dfrac{\tau}{2} - \dfrac{\sin\left(20\tau\right)}{40}$\\
      \hline
      3 & $\dfrac{\frac{\cos^3\left(10\tau\right)}{3} - \cos\left(10\tau\right)}{10}$\\
      \hline
      4 & $\dfrac{120\tau - 8\sin\left(20\tau\right) + \sin\left(40\tau\right)}{320}$\\
      \hline
      5 & $\dfrac{-\frac{\cos^5\left(10\tau\right)}{5} + \frac{2\cos^3\left(10\tau\right)}{3}- \cos\left(10\tau\right)}{10}$\\
      \hline
      6 & $\dfrac{600\tau + 4\sin^3\left(20\tau\right) - 48\sin\left(20\tau\right) + 9\sin\left(40\tau\right)}{1920}$\\
      \hline
      7 & $\dfrac{\frac{\cos^7\left(10\tau\right)}{7} - \frac{3\cos^5\left(10\tau\right)}{5} + \cos^3\left(10\tau\right) - \cos\left(10\tau\right)}{10}$\\
      \hline
      8 & $\dfrac{8400\tau + 128\sin^3\left(20\tau\right) - 768\sin\left(20\tau\right) + 168\sin\left(40\tau\right) + 3\sin\left(80\tau\right)}{30720}$\\
      \hline
  \end{tabular}
  \caption{Trig integrals for powers of $n \in [0,8] \in \mathbb{Z}$.}
\end{table}
\end{document}

cellspace 包示例

答案2

虽然有点晚了,但希望还是有用的。我建议不要集中精力实现连续水平线之间的垂直居中,而是去掉水平线(以及垂直线)。这种方法还可以让我去掉所有[12pt]间隔符。

接下来,那些长长的分数线看起来非常吓人。我认为你的读者会感谢你\frac{<very long numerator>{<short denominator>}用表达式代替\frac{1}{<short denominator>}[<very long numerator>]表达式。

我还会使用longtable环境而不是table/tabular组合,以便在需要时自动分页。

最后,摆脱大量的\left\right尺寸指令:他们完成没有什么—— 除了扰乱 TeX 的精细水平间距规则。

在此处输入图片描述


在此处输入图片描述

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry} 
\usepackage{mathtools, amssymb, bm, graphicx}
\usepackage{array, booktabs, longtable}
\setlength\LTcapwidth{\textwidth}
\usepackage{float,enumitem, interval}
\intervalconfig{soft open fences,separator symbol=, } 

\newcommand\mymat{%
\begin{bmatrix*}[r]
          1 &   \sin(10t) & \sin^2(10t) & \sin^3(10t) & \sin^4(10t)\\
  \sin(10t) & \sin^2(10t) & \sin^3(10t) & \sin^4(10t) & \sin^5(10t)\\
\sin^2(10t) & \sin^3(10t) & \sin^4(10t) & \sin^5(10t) & \sin^6(10t)\\
\sin^3(10t) & \sin^4(10t) & \sin^5(10t) & \sin^6(10t) & \sin^7(10t)\\
\sin^4(10t) & \sin^5(10t) & \sin^6(10t) & \sin^7(10t) & \sin^8(10t)
\end{bmatrix*}}

\begin{document}
\title{\vspace{-2cm}HW 8}
\author{John Doe}
\date{\today}
\maketitle

\begin{enumerate}[left=0pt]
\item Looking at $x$, we see that $T = 0.2\pi$, so $x = \sin(10t)$. Therefore, 
\[
\bm{\Phi}(t) = 
\begin{bmatrix} 
1 & \sin(10t) & \sin^2(10t) & \sin^3(10t) & \sin^4(10t)
\end{bmatrix}^T
\]
Next,
\[
\bm{\Phi}(t)\bm{\Phi}^T\!(t) = \mymat
\]

Then, the PE condition is evaluated as
\[
\int_{t}^{t+T}\bm{\Phi}(\tau)\bm{\Phi}^T\!(\tau)\, d\tau=
\int_{t}^{t+T} \mymat d\tau
\]
The following table shows the trig integrals for various powers of $n$.
\begin{longtable}{@{} >{$}l<{$} >{$\displaystyle}l<{$} @{}}
\caption{Trig integrals for powers of $n \in \{0,1,\dots,8\} \subset \mathbb{Z}$.}\\
\toprule
n & \int\sin^n(10\tau)\,d\tau\\ \addlinespace
\midrule
0 & \tau\\ \addlinespace
1 & -\frac{1}{10}\cos(10\tau) \\ \addlinespace
2 & \frac{\tau}{2} - \frac{1}{40}\sin(20\tau) \\ \addlinespace
3 & \frac{1}{10}\bigl[\tfrac{1}{3}\cos^3(10\tau) - \cos(10\tau)\bigr] \\ \addlinespace
4 & \frac{1}{320}\bigl[120\tau - 8\sin(20\tau) + \sin(40\tau)\bigr] \\ \addlinespace
5 & \frac{1}{10}\bigl[-\tfrac{1}{5}\cos^5(10\tau) + \tfrac{2}{3}\cos^3(10\tau)- \cos(10\tau) \bigr] \\ \addlinespace
6 & \frac{1}{1920}\bigl[600\tau + 4\sin^3(20\tau) - 48\sin(20\tau) + 9\sin(40\tau) \bigr]\\ \addlinespace
7 & \frac{1}{10}\bigl[ \tfrac{1}{7}\cos^7(10\tau) - \tfrac{3}{5}\cos^5(10\tau) + \cos^3(10\tau) - \cos(10\tau) \bigr] \\ \addlinespace
8 & \frac{1}{30720}\bigl[8400\tau + 128\sin^3(20\tau) - 768\sin(20\tau) + 168\sin(40\tau) + 3\sin(80\tau) \bigr] \\\addlinespace 
\bottomrule
\end{longtable}

With $T = 0.2\pi$ and applying the integral bounds, we get:
\begin{longtable}{@{} >{$}l<{$} >{$\displaystyle}l<{$} @{}}
\toprule
n & \int_{t}^{t+T} \sin^n(10\tau)\,d\tau \\ \addlinespace
\midrule
1,3,5,7 & 0 \\\addlinespace
0 & 0.2\pi \\ \addlinespace
2 & 0.1\pi \\ \addlinespace
4 & (3/40) \pi \\ \addlinespace
6 & (1/16)\pi\\ \addlinespace
8 & (7/128)\pi \\ 
\bottomrule
\end{longtable}
\end{enumerate}
\end{document}

答案3

除了@muzimuzhi 提供的关于 cellspace 的优秀解决方案之外,我还添加了 \makegapedcell 选项——请看一下

你可以添加 \addlinespace 作为第三个选项,以使用 booktabs 包获得额外的空间,但缺点是你必须删除 \hline,否则会显示间隙

我已经删除了一些软件包,并且删除了n第一列中的 unicode 错误,因为这些错误会被抛出——我相信你会恢复的

在此处输入图片描述

平均能量损失

\documentclass{article}
\usepackage{amsmath,amsfonts}
\usepackage{booktabs}
\usepackage[column=o]{cellspace}%
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\usepackage{makecell}
\setcellgapes{3pt}
\usepackage[american,siunitx]{circuitikz}
\usepackage{mathtools}
\usepackage{relsize}
\usepackage[margin=1in]{geometry} 
\let\DeclareUSUnit\DeclareSIUnit
\let\US\SI
\DeclareUSUnit\mile{mi}

\begin{document}
\begin{table}[!htbp]
            \centering
            \begin{tabular}{|oc|oc|}
                \hline
                & $\mathlarger{\int\sin^n\left(10\tau\right)d\tau}$\\
                \hline
                0 & $\tau$\\
                \hline
                1 & $-\dfrac{\cos\left(10\tau\right)}{10}$\\
                \hline
                2 & $\dfrac{\tau}{2} - \dfrac{\sin\left(20\tau\right)}{40}$\\
                \hline
            \end{tabular}
\end{table}
\begin{table}[!htbp]            
            \centering\makegapedcells
            \begin{tabular}{|c|c|}
                \hline
                & $\mathlarger{\int\sin^n\left(10\tau\right)d\tau}$\\
                \hline
                0 & $\tau$\\
                \hline
                1 & $-\dfrac{\cos\left(10\tau\right)}{10}$\\
                \hline
                2 & $\dfrac{\tau}{2} - \dfrac{\sin\left(20\tau\right)}{40}$\\
                \hline
            \end{tabular}
\end{table}
\end{document} 

相关内容