2

my code is

\renewcommand{\arraystretch }{1.2}
\begin{table}[h]
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{Altitude (km)}&\multicolumn{2}{|c|}{Temperature (\degree C)}&\thead{Lapse rate\\ (K/km)} &\\
\cline{1-4}
\multicolumn{1}{c|}{from}&\multicolumn{1}{c|}{to}&\multicolumn{1}{c|}{from}&\multicolumn{1}{c|}{to}& &\\
\hline\hline
0 &11 &15 &$-56.5$& $-6.5$& troposphere\\\hline
11 &20 &$-$56.5& $-$56.5& 0 &stratosphere\\\hline
20 &32 &$-$56.5& $-$44.5& 1.0& stratosphere\\\hline
32 &47 &$-$44.5 &$-$2.5& 2.8& stratosphere\\\hline
47 &52 &$-$2.5 &$-$2.5 &0 &mesosphere\\\hline
52 &61 &$-$2.5 &$-$20.5& $-$2.0& mesosphere\\\hline
61 &79 &$-$20.5 &$-$92.5 &$-$4.0 &mesosphere\\\hline
79 &90 &$-$92.5& $-$92.5& 0 &thermosphere\\
\hline
\end{tabular}
\end{center}
\end{table}

and i want my table to look like thisenter image description here

4
  • How or where is \degree defined?
    – Mico
    Aug 11, 2021 at 20:22
  • in the preamble of my code i have included the package \usepackage{gensymb} Aug 11, 2021 at 20:26
  • To get the expected output, use \multicolumn{1}{|c|}{from}, \multicolumn{2}{c|}{Temperature (°C)} and \multirow{2}{*}{\thead{Lapse rate\\ (K/km)}}(Requires the multirow package).
    – leandriis
    Aug 11, 2021 at 20:27
  • i have used this package multirow but i still cant achieve the above results Aug 11, 2021 at 20:32

2 Answers 2

2

I take it that your main formatting requirement is to align the numbers in the data columns on their respective explicit or implicit decimal markers. I would like to suggest an approach which, while achieving this objective, does not make the table look like a prison cell window with lots and lots of vertical and horizontal bars.

enter image description here

\documentclass{article}
\usepackage{siunitx}  % for 'S' column type and \si macro
\usepackage{booktabs} % for \toprule, \midrule, \cmidrule, \bottomrule, and \addlinespace macros
\usepackage{amsmath}  % for \smash[b] macro
\sisetup{per-mode=symbol}
\newcommand\mytab[1]{\smash[b]{%
    \begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{@{} *{2}{S[table-format= 2.0]} 
                    *{2}{S[table-format=-2.1]} 
                         S[table-format=-1.1] 
                         l @{}}
\toprule
\multicolumn{2}{@{}c}{Altitude (\si{\kilo\meter})}&
\multicolumn{2}{c}{Temp.\ (\si{\celsius})}&
{\mytab{Lapse rate \\ (\si{\kelvin\per\kilo\meter})}} \\
\cmidrule(r){1-2} \cmidrule(lr){3-4} 
{from} & {to} & {from} & {to}  \\
\midrule
 0 &11 & 15   & -56.5 & -6.5 & troposphere\\  \addlinespace
11 &20 &-56.5 & -56.5 &  0   & stratosphere\\
20 &32 &-56.5 & -44.5 &  1.0 & stratosphere\\
32 &47 &-44.5 &  -2.5 &  2.8 & stratosphere\\ \addlinespace
47 &52 & -2.5 &  -2.5 &  0   & mesosphere\\
52 &61 & -2.5 & -20.5 & -2.0 & mesosphere\\
61 &79 &-20.5 & -92.5 & -4.0 & mesosphere\\   \addlinespace
79 &90 &-92.5 & -92.5 &  0   & thermosphere\\
\bottomrule
\end{tabular}
\end{table}

\end{document}
0

I propose this variant layout, using some colour:

\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs} %
\usepackage{makecell, multirow}
\usepackage[svgnames, table]{xcolor}
\usepackage{amsmath} % for \smash[b] macro
\sisetup{per-mode=symbol}

\begin{document}

\begin{table}[h]
\centering
\begin{tabular}{@{}>{\columncolor{WhiteSmoke}[0pt][\tabcolsep]}S[table-format= 2.0] >{\columncolor{Gainsboro}}S[table-format= 2.0]>{\columncolor{WhiteSmoke}[0pt][\tabcolsep]}S[table-format= -2.1] >{\columncolor{Gainsboro}}S[table-format= -2.1]
        >{\columncolor{WhiteSmoke}[0pt][\tabcolsep]}S[table-format=-1.1]
                         l @{}}
\rowcolor{White}\multicolumn{2}{@{}c}{\makecell{Altitude\\ (\unit{\km})}}&
\multicolumn{2}{c}{\makecell{Temperature\\ (\unit{\degreeCelsius})}}&
{\multirowcell{4}{Lapse rate \\ (\unit{\K\per\km})}} \\
\cmidrule(r){1-2} \cmidrule(lr){3-4}
\rowcolor{White}{from} & {to} & {from} & {to} \\
\midrule[\heavyrulewidth]
 0 &11 & 15 & -56.5 & -6.5 & troposphere\\[1ex]
11 &20 &-56.5 & -56.5 & 0 & stratosphere\\
20 &32 &-56.5 & -44.5 & 1.0 & stratosphere\\
32 &47 &-44.5 & -2.5 & 2.8 & stratosphere\\[1ex]
47 &52 & -2.5 & -2.5 & 0 & mesosphere\\
52 &61 & -2.5 & -20.5 & -2.0 & mesosphere\\
61 &79 &-20.5 & -92.5 & -4.0 & mesosphere\\[1ex]
79 &90 &-92.5 & -92.5 & 0 & thermosphere\\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.