2

How do i get the table output like this? I tried following few threads in this forum. But couldn't help to ask this question. Help me out guys !! Thanks in advance :)

Tabl 3.1

  • 9
    On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – jub0bs Apr 22 '14 at 12:20
  • Yeah I agree. But I would have asked "How do i get a double horizontal line in a table?" and then to get an output simliar to above picture. Changing the question would have given me the same answer. Anyway thanks for suggesting :) – walterhunk Apr 22 '14 at 13:02
  • 1
    @Jubobs it's not really true.... and is your question How was this tip box produced? any different (did you post any code)? I'm not trying to start an argument, just pointing out that sometimes a user honestly doesn't know where to start, and our site helps that user move forward – cmhughes Apr 23 '14 at 14:28
  • @cmhughes My problem with this question is that the actual problem is not spelled out clearly. The OP didn't point to a specific issue s/he was having, but just posted a screenshot. In the question of mine that you're referring to, note that I wasn't actually asking for code, just pointers as to how to draw the bit where "Tip" is written; that's why I didn't post an MWE. I was surprised to see Gonzalo post such a thorough answer, but I wasn't asking for so much. – jub0bs Apr 23 '14 at 15:10
  • @cmhughes Sorry, I didn't mean to sound confrontational. We can discuss this in the chat room, if you want. – jub0bs Apr 25 '14 at 15:55
15

Example, the numbers are aligned at the decimal dot using package siunitx' column specifier S:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\newcommand*{\mytablehead}[1]{%
  \renewcommand*{\arraystretch}{1.5}%
  \bfseries
  \begin{tabular}{@{}c@{}}#1\end{tabular}%
}
\renewcommand*{\arraystretch}{1.2}
\begin{tabular}{|c|S|S|S|S|}
  \hline
  \multicolumn{1}{|c|}{\mytablehead{\mbox{}\\Specimen No.}}&
  \multicolumn{2}{c|}{\mytablehead{With End-effect-\\Correction}}&
  \multicolumn{2}{c|}{\mytablehead{Without End-effect-\\Correction}}\\
  \cline{2-5}
  & \multicolumn{1}{c|}{Sa(\si{\micro\metre})}
  & \multicolumn{1}{c|}{Sz(\si{\micro\metre})}
  & \multicolumn{1}{c|}{Sa(\si{\micro\metre})}
  & \multicolumn{1}{c|}{Sz(\si{\micro\metre})} \\
  \hline
  1 & 6.41 & 42.9 & 6.46 & 43.86 \\
  \hline
  2 & 5.04 & 36.07 & 5.74 & 52.16 \\
  \hline
  3 & 7.45 & 48.23 & 7.62 & 48.22 \\
  \hline
  4 & 5.93 & 44.74 & 6.5 & 48.1 \\
  \hline
  5 & 7.38 & 46.66 & 6.94 & 43.7 \\
  \hline
  Average & 6.442 & 43.72 & 6.652 & 47.208 \\
  \hline
\end{tabular}
\end{document}

Result

A variant without excessive lines:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\newcommand*{\mytablehead}[2]{%
  \multicolumn{#1}{c}{%
    \bfseries
    \begin{tabular}{@{}c@{}}#2\end{tabular}%
  }%
}
\renewcommand*{\arraystretch}{1.2}
\begin{tabular}{cSSSS}
  \toprule
  \mytablehead{1}{\mbox{}\\Specimen No.}&
  \mytablehead{2}{With End-effect-\\Correction}&
  \mytablehead{2}{Without End-effect-\\Correction}\\
  & \multicolumn{1}{c}{Sa(\si{\micro\metre})}
  & \multicolumn{1}{c}{Sz(\si{\micro\metre})}
  & \multicolumn{1}{c}{Sa(\si{\micro\metre})}
  & \multicolumn{1}{c}{Sz(\si{\micro\metre})} \\
  \midrule
  1 & 6.41 & 42.9 & 6.46 & 43.86 \\
  2 & 5.04 & 36.07 & 5.74 & 52.16 \\
  3 & 7.45 & 48.23 & 7.62 & 48.22 \\
  4 & 5.93 & 44.74 & 6.5 & 48.1 \\  
  5 & 7.38 & 46.66 & 6.94 & 43.7 \\
  Average & 6.442 & 43.72 & 6.652 & 47.208 \\
  \bottomrule
\end{tabular}
\end{document}

Result

  • Simply superb \m/... Thanks a lot @Heiko. You have just made my task simpler and in a fully understandable way :). Good explanation :) – walterhunk Apr 22 '14 at 12:57
  • What a nice trick, based on the equivalence of vertical centering of Specimen No. and aligning it with Correction in this case! – Przemysław Scherwentke Apr 22 '14 at 13:04
  • 1
    One can see an excessive width in vertical lines in the two first line or is it an effect of the bitmap convertion ? – Tarass Apr 22 '14 at 13:25

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.