3

I want to insert headers in table, but somehow I am not able to do so. The bold line in below text, I want these to just insert between rows as headers. From below code, column from 2nd to last are shifted far beyond page. I think this is due to these line are considered as row elements not just a header line. Please help.

\begin{tabular}{l*{6}{c}r}\hline
Data set & EPMM & BCC & TEST1 & TEST2 & TEST3 \\ \hline

IN first run of experiment with 100 ml solute \\

MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME  & 1.4 & 1.4 & 1.5 & 1.8 & \<b>
`IN second run of experiment with 200 ml solute\\`

MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME  & 1.4 & 1.4 & 1.5 & 1.8 & \<b>
`In third run of experiment with 300 ml solute\\`

MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME  & 1.4 & 1.4 & 1.5 & 1.8 & \\
overall MAE & 0.80 & 3.06 & 2.65 & 3.04 & 3.13 \\
overall ME  & 0.11 & 3.03 & 2.63 & 2.00 & 3.13  \\ \hline
\end{tabular}
1
  • 1
    Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. Commented Jun 4, 2013 at 12:57

2 Answers 2

5

\multicolumn is your friend, e.g.:

\documentclass{article}
\begin{document}
\begin{tabular}{l*{6}{c}}\hline
Data set & EPMM & BCC & TEST1 & TEST2 & TEST3 \\ \hline
\noalign{\vspace{1ex}}
\multicolumn{6}{l}{\textbf{%
  In first run of experiment with 100 ml solute}} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME & 1.4 & 1.4 & 1.5 & 1.8 & \\[1ex]
\multicolumn{6}{l}{\textbf{%
  In second run of experiment with 200 ml solute}} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME & 1.4 & 1.4 & 1.5 & 1.8 & \\[1ex]
\multicolumn{6}{l}{\textbf{%
  In third run of experiment with 300 ml solute}} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME & 1.4 & 1.4 & 1.5 & 1.8 & \\
overall MAE & 0.80 & 3.06 & 2.65 & 3.04 & 3.13 \\
overall ME & 0.11 & 3.03 & 2.63 & 2.00 & 3.13 \\ \hline
\end{tabular}
\end{document}

Result

Remarks:

  • I have added some space above the bold lines. It can be done by adding the space in the optional argument of \\. In the first case, there is an \hline inbetween, therefore the space is added via \vspace, smuggled in via \noalign that can be used at the very beginning of a line.

  • The example uses six columns without the unused seventh column.

Example that aligns the decimal numbers on the dot separator

The example uses package dcolumn and the D column specifier. The header line shows another use case for \multicolumn. It can also be uses for one cell for overriding the column specification of the cell.

\documentclass{article}
\usepackage{dcolumn}
\begin{document}
\begin{tabular}{l*{5}{D{.}{.}{2}}}\hline
Data set &
  \multicolumn{1}{l}{EPMM} &
  \multicolumn{1}{l}{BCC} &
  \multicolumn{1}{l}{TEST1} &
  \multicolumn{1}{l}{TEST2} &
  \multicolumn{1}{l}{TEST3} \\ \hline
\noalign{\vspace{1ex}}
\multicolumn{6}{l}{\textbf{%
  In first run of experiment with 100 ml solute}} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME & 1.4 & 1.4 & 1.5 & 1.8 & \\[1ex]
\multicolumn{6}{l}{\textbf{%
  In second run of experiment with 200 ml solute}} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME & 1.4 & 1.4 & 1.5 & 1.8 & \\[1ex]
\multicolumn{6}{l}{\textbf{%
  In third run of experiment with 300 ml solute}} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME & 1.4 & 1.4 & 1.5 & 1.8 & \\
overall MAE & 0.80 & 3.06 & 2.65 & 3.04 & 3.13 \\
overall ME & 0.11 & 3.03 & 2.63 & 2.00 & 3.13 \\ \hline
\end{tabular}
\end{document}

Result

0
4

You can get better results with booktabs and siunitx. For the headers, use \multicolumn:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{caption}
\captionsetup[table]{position=above}

\begin{document}
\begin{table}
\sisetup{detect-all} % we want \SI to respect font attributes

\centering

\caption{Results of the experiments}\label{tab:results}

\begin{tabular}{l*{5}{S[table-format=1.2]}}
\toprule
Data set & {EPMM} & {BCC} & {TEST1} & {TEST2} & {TEST3} \\
\midrule
\multicolumn{6}{c}{\bfseries
  In first run of experiment with \SI{100}{ml} solute} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 \\
ME  & 1.4 & 1.4 & 1.5 & 1.8 \\
\midrule
\multicolumn{6}{c}{\bfseries
  In second run of experiment with \SI{200}{ml} solute} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME  & 1.4 & 1.4 & 1.5 & 1.8 & \\
\midrule
\multicolumn{6}{c}{\bfseries
  In third run of experiment with \SI{300}{ml} solute} \\
MAE & 1.4 & 1.4 & 1.5 & 1.8 & \\
ME  & 1.4 & 1.4 & 1.5 & 1.8 & \\
\midrule
overall MAE & 0.80 & 3.06 & 2.65 & 3.04 & 3.13 \\
overall ME  & 0.11 & 3.03 & 2.63 & 2.00 & 3.13  \\
\bottomrule
\end{tabular}

\end{table}
\end{document}

enter image description here

Notice that with the S-column type provided by siunitx you get alignment at the decimal point.

You must log in to answer this question.

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