7

As in the title, I find these two tables really ugly. Any suggestions to make them look better?

\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}
6
  • 2
    Remove the vertical lines -- they look ugly in most cases and in conjunction with booktabs they're blasphemous. Also use the S type for the numbers from siunitx package, also for the units
    – user31729
    Commented Aug 29, 2017 at 14:17
  • I would like to keep these or at least change the layout since i need a good separation of the text
    – me8
    Commented Aug 29, 2017 at 14:18
  • 1
    Will you have a caption? Have you any reason to let the tables float?
    – Bernard
    Commented Aug 29, 2017 at 14:21
  • Yes i do, i have a caption and a label..
    – me8
    Commented Aug 29, 2017 at 14:22
  • Please, don't use "sec" for second. The correct symbol is "s", and if you use the siunitx package it will take care of this automatically. Commented Aug 29, 2017 at 18:31

3 Answers 3

8

I propose this:

\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}

enter image description here

If you want some colour, you can have this:

\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} 

enter image description here

2
  • Very nice, but \si{\mm\per\!\min} might look slightly nicer...
    – Thruston
    Commented Aug 29, 2017 at 16:28
  • @Thruston: That's right. I've fixed this in the coloured version. How comes the maintainers of siunitx didn't notice the problem?
    – Bernard
    Commented Aug 29, 2017 at 16:36
3

A version that merges both tables to one table to get the formula in the same column as the calculated value:

\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}

Result

Without number alignemnt, because the number in a column have different units and are therefore not comparable.

\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}

Result without number alignment

With repeated units:

\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}

Result with repeated units

0
2

Here's a solution suggestion that's quite similar, overall, to Bernard's, with the following exceptions:

  • Use an array environment instead of a tabular (or matrix) env.

  • Omit all instances of \cdot

  • Snug up the "crit" subscripts to the letters "P" and "T", resp.

  • Use \dfrac in the upper table.

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .