需要有关基本表格的帮助

需要有关基本表格的帮助

我是初学者。过去两天我一直在尝试制作一张表格,但一直没有成功。我需要这张表格方面的帮助。桌子

我的一些尝试

\begin{tabular}{|c|c|c|c|c|}
\hline
$t$ & $y$ & $y$ \text{in terms of} $y_0[=(-\frac 12) 

g\tau^2]$ &\text{Distance traversed in successive intervals}& \text{Ratio of distances traversed} \
\hline
 $0$ & $0$ & $0$ & $:$ & $:$  \
$ \tau$  & $-(\frac 12) g \tau^2$ & $y_0$ & $y_0$ & $1$\
 $2 \tau$ & $-4(\frac 12) g \tau^2$ & $4y_0$ & $3y_0$ & $3$ \
 $3 \tau$ & $-9(\frac 12) g \tau^2$ & $9y_0$ & $5y_0$ & $5$  \
 $4\tau$ & $-16(\frac 12) g \tau^2$ & $16y_0$ &$7y_0$ & $7$  \
 $5 \tau$ & $-25(\frac 12) g \tau^2$ & $25y_0$ & $9y_0$ & $9$ \
 $6 \tau$ & $-36(\frac 12) g \tau^2$& $36y_0$ & $11y_0$ & $11$
\end{tabular}

\begin{tabular}{|c|c|c|c|c|}
\hline
$t$ & $y$ & $y$ \text{in terms of} $y_0[=\left(-\frac 12\right) g\tau^2]$ &\text{Distance traversed in successive intervals}& \text{Ratio of distances traversed} \
\hline
 $0$ & $0$ & $0$ & $:$ & $:$  \
$ \tau$  & $-\left(\frac 12\right) g \tau^2$ & $y_0$ & $y_0$ & $1$\
 $2 \tau$ & $-4\left(\frac 12\right) g \tau^2$ & $4y_0$ & $3y_0$ & $3$ \
 $3 \tau$ & $-9\left(\frac 12\right) g \tau^2$ & $9y_0$ & $5y_0$ & $5$  \
 $4\tau$ & $-16\left(\frac 12\right) g \tau^2$ & $16y_0$ &$7y_0$ & $7$  \
 $5 \tau$ & $-25\left(\frac 12\right) g \tau^2$ & $25y_0$ & $9y_0$ & $9$ \
 $6 \tau$ & $-36\left(\frac 12\right) g \tau^2$& $36y_0$ & $11y_0$ & $11$ \
\hline
\end{tabular}

\begin{tabular}{|c|c|c|c|c|}
\hline
$t$ & $y$ & $y$ \text{in terms of} $y_0[=\left(-\frac 12\right) g\tau^2]$ &\text{Distance traversed in successive intervals}& \text{Ratio of distances traversed} \\
\hline
 $0$ & $0$ & $0$ & $\:$ & $\:$  \\
$ \tau$  & $-\left(\frac 12\right) g \tau^2$ & $y_0$ & $y_0$ & $1$\\
 $2 \tau$ & $-4\left(\frac 12\right) g \tau^2$ & $4y_0$ & $3y_0$ & $3$ \\
 $3 \tau$ & $-9\left(\frac 12\right) g \tau^2$ & $9y_0$ & $5y_0$ & $5$  \\
 $4\tau$ & $-16\left(\frac 12\right) g \tau^2$ & $16y_0$ &$7y_0$ & $7$  \\
 $5 \tau$ & $-25\left(\frac 12\right) g \tau^2$ & $25y_0$ & $9y_0$ & $9$ \\
 $6 \tau$ & $-36\left(\frac 12\right) g \tau^2$& $36y_0$ & $11y_0$ & $11$ \\
\hline
\end{tabular}

答案1

以下是一种方法:

\documentclass[12pt]{article}
%\usepackage{amsmath}   % in case you need it
\begin{document}
    \begin{tabular}{|l|l|p{2cm}|p{2.5cm}|p{3cm}|} % p: col-width
        \hline
        $t$ & 
        $y$ & 
        {$y$ in terms of $y_0=-\frac{1}{2} g \tau^2$} &
        {Distance traversed in successive intervals} & % {} for readability
        {Ratio of distances traversed}\\% \\ ends the row
        
        \hline  % just two lines as an example
        $0$ &$0$ &$0$ &$0$ &$0$\\    % digits in math-font
        $6 \tau$ & 
        $-3 (\frac{1}{2})g \tau^2$ & % watch braces ;-)
        {$36 y_0$} & {$11 y_0$} &
        {$11$}\\
        \hline
    \end{tabular}
\end{document}

https://en.wikibooks.org/wiki/LaTeX/Tables#The_tabular_environment了解有关tabular环境的更多详细信息。

结果:

在此处输入图片描述

除非你已经知道,否则这个值得花几个小时阅读和扫描:https://en.wikibooks.org/wiki/LaTeX

在这里可以找到更多表格设计的替代方案:https://ctan.org/topic/table?lang=en. 也许你会喜欢nicematrix https://ctan.org/pkg/nicematrix

祝您与 Latex 的旅程愉快 :)

答案2

不清楚为什么您的代码片段有三个连续相同的表。无论如何,建议的解决方案是只考虑一个:

在此处输入图片描述

在上面表格的代码中,我们考虑了在数学环境中嵌套的tblr包中定义的表环境tabularray。这样就消除了$表体中的所有内容:

编辑: 在 MWE 中现在被认为是tabularray2021N 版本。

\documentclass{article}
\usepackage{tabularray}

\begin{document}
\[
\begin{tblr}{colspec = { l l  X[l] X[1.1,l] X[l] },
             vlines,
             hline{1,2,Z} = {1pt},  % <---
             colsep=4pt,
             }
t   & y &   y $ in terms of $ y_0\ [=(-\frac{1}{2})g\tau^2] 
            &   $in terms of successive intervals$~
                &   $Ratio of distances traversed$~   \\
0   & 0 & 0 &   &                           \\
\tau  & -(\frac{1}{2}) g \tau^2 
        & y_0   & y_0 & 1                   \\
2\tau & -4(\frac{1}{2}) g \tau^2
        & 4y_0 & 3y_0 & 3     \\
3\tau & -9(\frac{1}{2}) g \tau^2
        & 9y_0 & 5y_0 & 5     \\
4\tau & -16(\frac{1}{2}) g \tau^2
        & 16y_0 &7y_0 & 7     \\
5\tau & -25(\frac{1}{2}) g \tau^2
        & 25y_0 & 9y_0 & 9    \\
6\tau & -36(\frac{1}{2}) g \tau^2
        & 36y_0 & 11y_0 & 11  \\
\end{tblr}
\]
\end{document}

答案3

要在列标题中创建多行,可以使用包\thead中的命令。makecell

\documentclass{article}

\usepackage{makecell}
\usepackage{amsmath}

\renewcommand\theadalign{tl} %for top left alignment

\begin{document}
\begin{tabular}{|l|l|l|l|l|}
\hline
\thead{$t$} & \thead{$y$} 
& \thead{$y$ in terms of\\ $y_0[=\left(-\frac 12\right) g\tau^2]$} 
& \thead{Distance \\traversed in \\successive \\intervals} 
& \thead{Ratio of \\distances \\traversed} \\
\hline
$0$ & $0$ & $0$ & $\:$ & $\:$  \\
$ \tau$  & $-\left(\frac 12\right) g \tau^2$ & $y_0$ & $y_0$ & $1$ \\
$2 \tau$ & $-4\left(\frac 12\right) g \tau^2$ & $4y_0$ & $3y_0$ & $3$ \\
$3 \tau$ & $-9\left(\frac 12\right) g \tau^2$ & $9y_0$ & $5y_0$ & $5$  \\
$4\tau$ & $-16\left(\frac 12\right) g \tau^2$ & $16y_0$ &$7y_0$ & $7$  \\
$5 \tau$ & $-25\left(\frac 12\right) g \tau^2$ & $25y_0$ & $9y_0$ & $9$ \\
$6 \tau$ & $-36\left(\frac 12\right) g \tau^2$& $36y_0$ & $11y_0$ & $11$ \\
\hline
\end{tabular}
\end{document}

输出

相关内容