如何让这两个表格看起来更好看呢?

如何让这两个表格看起来更好看呢?

正如标题所示,我发现这两个表格真的很丑。有什么建议可以让它们看起来更好吗?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}

\begin{document}

\begin{table}[!h]
\centering
\begin{tabular}{c|c|c|c|c}
    \toprule
     & \(P\) & \(PI\) & \(PD\) & \(PID\) \\
    \midrule
    \(P\) & \(0.5\cdot P_{crit}\) & \(0.45\cdot P_{crit}\) & \(0.5\cdot P_{crit}\) & \(0.6\cdot P_{crit}\)  \\
    \midrule
    \(I\) &  & \(\frac{P}{0.85\cdot T_{crit}}\) &  & \(\frac{P}{0.5\cdot T_{crit}}\) \\
    \midrule
    \(D\) & & & \(0.2\cdot T_{crit}\cdot P\) & \(0.12\cdot T_{crit}\cdot P\) \\
    \bottomrule
\end{tabular}
\end{table} 

\begin{table}[!h]
\centering
\begin{tabular}{c|c|c|c|c|c}
    \toprule
     & \shortstack{Unità di\\ misura}& \(P\) & \(PI\) & \(PD\) & \(PID\) \\
    \midrule
    \(P\) & \(\frac{mm}{min}\)&\(110\) & \(99\) & \(110\) & \(132\)  \\
    \midrule
    \(I\) & \(\frac{mm}{min\cdot sec}\) &  & \(247.8\) &  & \(468.1\) \\
    \midrule
    \(D\) & \(\frac{mm\cdot sec}{min}\) & & & \(10.3\) & \(7.5\) \\
    \bottomrule
\end{tabular}
\end{table}

\end{document}

答案1

我建议这样做:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{nccmath}
\usepackage{booktabs, siunitx}

\begin{document}

\begin{table}[!h]
\centering
 $ \begin{matrix}
    \toprule
     & P & PI & PD & PID \\
    \midrule
    P & 0.5\cdot P_\text{crit} & 0.45\cdot P_\text{crit} & 0.5\cdot P_\text{crit} & 0.6\cdot P_\text{crit} \\
    \addlinespace
    I & & \mfrac{P}{0.85\cdot T_\text{crit}} & & \mfrac{P}{0.5\cdot T\text{crit}} \\
    \addlinespace
    D & & & 0.2\cdot T_\text{crit}\cdot P & 0.12\cdot T_\text{crit}\cdot P \\
    \bottomrule
\end{matrix}$
\end{table}

\begin{table}[!h]
\centering\sisetup{per-mode=fraction}
\begin{tabular}{ >{$}l<{$}l*{4}{S[table-format=3.1, table-alignment=center]}}
    \toprule
     & \shortstack{Unità di\\ misura}& {P} & {PI} & {PD} & {PID} \\
    \midrule
    P &\si{mm\per\!\min}&110 & 99 & 110 & 132 \\
    \addlinespace
    I & \si{mm\per\!\min\,\s} & & 247.8 & & 468.1 \\
    \addlinespace
    D & \si{mm\s\per\!\min} & & & 10.3 & 7.5 \\
    \bottomrule
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

如果你想要一些颜色,你可以这样做:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{nccmath}
\usepackage{booktabs, siunitx}
\usepackage[table, svgnames]{xcolor}

\begin{document}

\begin{table}[!h]
\centering
 $ \begin{matrix}
    \toprule
     & P & PI & PD & PID \\
    \midrule
    \cellcolor{Gainsboro}P & 0.5 · P_\text{crit} & 0.45 · P_\text{crit} & 0.5 · P_\text{crit} & 0.6 · P_\text{crit} \\
    \addlinespace
    \cellcolor{Gainsboro}I & & \mfrac{P}{0.85 · T_\text{crit}} & & \mfrac{P}{0.5 · T\text{crit}} \\
    \addlinespace
    \cellcolor{Gainsboro}D & & & 0.2 · T_\text{crit} · P & 0.12 · T_\text{crit} · P \\
    \bottomrule
\end{matrix}$
\end{table}

\begin{table}[!h]
\centering\sisetup{per-mode=fraction}
\begin{tabular}{ >{\columncolor{Gainsboro}$}l<{$}l*{4}{S[table-format=3.1, table-alignment=center]}}
    \toprule
    % \cellcolor{white}& \shortstack{Unità di\\ misura}& {P} & {PI} & {PD} & {PID} \\
     \multicolumn{2}{c}{\cellcolor{white} Unità di misura}& {P} & {PI} & {PD} & {PID} \\
    \midrule
    P &\si{mm\per\!\min}&110 & 99 & 110 & 132 \\
    \addlinespace
    I & \si{mm\per\!\min\,\s} & & 247.8 & & 468.1 \\
    \addlinespace
    D & \si{mm\s\per\!\min} & & & 10.3 & 7.5 \\
    \bottomrule
\end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

答案2

将两个表合并为一个表以获得与计算值相同列中的公式的版本:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{amsmath}

\newcommand*{\Pcrit}{\ensuremath{P_{\text{crit}}}}
\newcommand*{\Tcrit}{\ensuremath{T_{\text{crit}}}}

\begin{document}
\begingroup
  \sisetup{per-mode=fraction}
  \def\NP{\mskip.5\thinmuskip}
  \begin{tabular}{
    l
    c
    S[table-format=3.0]
    S[table-format=3.1]
    S[table-format=3.1]
    S[table-format=3.1]
  }
    \toprule
    & \shortstack{Unità di\\ misura} & {$P$} & {$PI$} & {$PD$} & {$PID$} \\
    \midrule
    $P$ &
    & {$0.5\NP\Pcrit$} & {$0.45\NP\Pcrit$}
    & {$0.5\NP\Pcrit$} & {$0.6\NP\Pcrit$} \\
    \addlinespace
    $I$ & & & {$\dfrac{P}{0.85\,\Tcrit}$} & & {$\dfrac{P}{0.5\,\Tcrit}$} \\
    \addlinespace
    $D$ & & & & {$0.2\,\Tcrit P$} & {$0.12\,\Tcrit P$} \\
    \midrule
    $P$ & \si{\milli\meter\per\minute} & 110 & 99 & 110 & 132 \\
    \addlinespace
    $I$ & \si{\milli\meter\per\minute\per\second} & & 247.8 & & 468.1 \\
    \addlinespace
    $D$ & \si{\milli\meter\second\per\minute} & & & 10.3 & 7.5 \\
    \bottomrule
  \end{tabular}
\endgroup
\end{document}

结果

没有数字对齐,因为同一列中的数字具有不同的单位,因此无法比较。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{amsmath}

\newcommand*{\Pcrit}{\ensuremath{P_{\text{crit}}}}
\newcommand*{\Tcrit}{\ensuremath{T_{\text{crit}}}}

\begin{document}
\begingroup
  \sisetup{per-mode=fraction}
  \def\NP{\mskip.5\thinmuskip}
  \begin{tabular}{lccccc}
    \toprule
    & \shortstack{Unità di\\ misura} & $P$ & $PI$ & $PD$ & $PID$ \\
    \midrule
    $P$ &
    & $0.5\NP\Pcrit$ & $0.45\NP\Pcrit$
    & $0.5\NP\Pcrit$ & $0.6\NP\Pcrit$ \\
    \addlinespace
    $I$ & & & $\dfrac{P}{0.85\,\Tcrit}$ & & $\dfrac{P}{0.5\,\Tcrit}$ \\
    \addlinespace
    $D$ & & & & $0.2\,\Tcrit P$ & $0.12\,\Tcrit P$ \\
    \midrule
    $P$ & \si{\milli\meter\per\minute} & 110 & 99 & 110 & 132 \\
    \addlinespace
    $I$ & \si{\milli\meter\per\minute\per\second} & & 247.8 & & 468.1 \\
    \addlinespace
    $D$ & \si{\milli\meter\second\per\minute} & & & 10.3 & 7.5 \\
    \bottomrule
  \end{tabular}
\endgroup
\end{document}

未进行数字对齐的结果

带有重复单元:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{amsmath}

\newcommand*{\Pcrit}{\ensuremath{P_{\text{crit}}}}
\newcommand*{\Tcrit}{\ensuremath{T_{\text{crit}}}}

\begin{document}
\begingroup
  \sisetup{per-mode=fraction}
  \def\NP{\mskip.5\thinmuskip}
  \def\UnitP{\si{\milli\meter\per\minute}}
  \def\UnitI{\si{\milli\meter\per\minute\per\second}}
  \def\UnitD{\si{\milli\meter\second\per\minute}}
  \begin{tabular}{lccccc}
    \toprule
    & \shortstack{Unità di\\ misura} & $P$ & $PI$ & $PD$ & $PID$ \\
    \midrule
    $P$ & \UnitP
    & $0.5\NP\Pcrit$ & $0.45\NP\Pcrit$
    & $0.5\NP\Pcrit$ & $0.6\NP\Pcrit$ \\
    \addlinespace
    $I$ & \UnitI & & $\dfrac{P}{0.85\,\Tcrit}$ & & $\dfrac{P}{0.5\,\Tcrit}$ \\
    \addlinespace
    $D$ & \UnitD & & & $0.2\,\Tcrit P$ & $0.12\,\Tcrit P$ \\
    \midrule
    $P$ & \UnitP & 110 & 99 & 110 & 132 \\
    \addlinespace
    $I$ & \UnitI & & 247.8 & & 468.1 \\
    \addlinespace
    $D$ & \UnitD & & & 10.3 & 7.5 \\
    \bottomrule
  \end{tabular}
\endgroup
\end{document}

重复单元的结果

答案3

这里有一个解决方案建议,总体上与 Bernard 的建议非常相似,但有以下几点不同:

  • 使用array环境而不是tabular(或matrix)环境。

  • 省略所有实例\cdot

  • 将“crit”下标分别贴到字母“P”和“T”上。

  • \dfrac在上表中使用。

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,amsmath,siunitx}
\begin{document}

\begin{table}[!h]
\centering
$\begin{array}{@{} l cccc @{}}
    \toprule
     & P & PI & PD & PID \\
    \midrule
    P & 0.5 P_{\!\mathrm{crit}} & 0.45 P_{\!\mathrm{crit}} 
      & 0.5 P_{\!\mathrm{crit}} & 0.6 P_{\!\mathrm{crit}}  \\
    \addlinespace
    I & & \dfrac{P}{0.85 T_{\mkern-1.5mu\mathrm{crit}}} 
      & & \dfrac{P}{0.5  T_{\mkern-1.5mu\mathrm{crit}}} \\
    \addlinespace
    D & & & 0.2  T_{\mkern-1.5mu\mathrm{crit}} P 
          & 0.12 T_{\mkern-1.5mu\mathrm{crit}} P \\
    \bottomrule
\end{array}$
\end{table} 

\begin{table}[!h]
\centering
$\begin{array}{@{} cc S[table-format=3.0] *{3}{S[table-format=3.1]} @{}}
    \toprule
     & \text{Unità di} & {P} & {PI} & {PD} & {PID} \\
     & \text{misura} \\
    \midrule
    P & \frac{\mathrm{mm}}{\mathrm{min}}               &110 & 99    & 110  & 132  \\
    \addlinespace
    I & \frac{\mathrm{mm}}{\mathrm{min}\,\mathrm{sec}} &    & 247.8 &      & 468.1\\
    \addlinespace
    D & \frac{\mathrm{mm}\,\mathrm{sec}}{\mathrm{min}} &    &       & 10.3 & 7.5  \\
    \bottomrule
\end{array}$
\end{table}

\end{document}

相关内容