需要帮助使我的文本居中

需要帮助使我的文本居中

这是我的代码:

\begin{flushleft}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
$x$&0&$\displaystyle\frac{\pi}{6}$&$\displaystyle\frac{\pi}{4}$&$\displaystyle\frac{\pi}{3}$&$\displaystyle\frac{\pi}{2}$&$\pi$\\ \hline
$\cos(x)$&1&$\displaystyle\frac{\sqrt3}{2}$&$\displaystyle\frac{\sqrt2}{2}$&$\displaystyle\frac{1}{2}$&0&-1\\ \hline
$\sin(x)$&0&$\displaystyle\frac{1}{2}$&$\displaystyle\frac{\sqrt2}{2}$&$\displaystyle\frac{\sqrt3}{2}$&1&0\\ \hline
$\tan(x$)&0&0&1&0&0&0\\ \hline
\end{tabular}
\end{center}
\end{flushleft}

答案1

我会简化表格的布局,取消所有垂直线和大部分水平线。由于所有内容都在数学模式下处理,因此我会使用环境array而不是tabular环境。

在此处输入图片描述

\documentclass{article}
\usepackage{array}
\usepackage{booktabs} % for \toprule, \midrule, \bottomrule, and \addlinespace macros
\begin{document}
\[
\begin{array}{@{} l *{6}{>{\displaystyle}c} @{}}
\toprule
x       & 0 &\frac{\pi}{6}   &\frac{\pi}{4}   &\frac{\pi}{3}   &\frac{\pi}{2}&\pi\\ 
\midrule
\cos(x) & 1 &\frac{\sqrt3}{2}&\frac{\sqrt2}{2}&\frac{1}{2}     &0            &-1 \\ 
\addlinespace
\sin(x) & 0 &\frac{1}{2}     &\frac{\sqrt2}{2}&\frac{\sqrt3}{2}&1            &0  \\ 
\addlinespace
\tan(x) & 0 &\frac{1}{\sqrt3}&1               &\sqrt3          &\infty       &0  \\ 
\bottomrule
\end{array}
\]
\end{document}

答案2

欢迎使用 TeX-SE!我只需添加一个表格并使用\centering它将其居中。您也可以使用array而不是手动在每个单元格中切换到数学模式。

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{table}[htb]
\centering\renewcommand{\arraystretch}{2}
$\begin{array}{|*7{>{\displaystyle\vphantom{\raisebox{2pt}{\Bigg[}}}c|}}
\hline
x&0&\frac{\pi}{6}&\frac{\pi}{4}&\frac{\pi}{3}&\frac{\pi}{2}&\pi\\
\hline
\cos(x)&1&\frac{\sqrt3}{2}&\frac{\sqrt2}{2}&\frac{1}{2}&0&-1\\
\hline
\sin(x)&0&\frac{1}{2}&\frac{\sqrt2}{2}&\frac{\sqrt3}{2}&1&0\\ 
\hline
\tan(x)&0&0&1&0&0&0\\ \hline
\end{array}$
\caption{\dots}
\end{table}
\end{document}

在此处输入图片描述

相关内容