1

Hi I am currently trying to create a table in latex that looks something like the table below:

table

So far I have been able to get this far but struggle to adjust the and Measure contribution header

\begin{center}
\begin{tabular}{|l|l|c|}
 \hline
\multicolumn{2}{|c|}{Element} & Measured Contribution\\
\hline
Magnesium & Mg & 23.124 \% \\
Aluminium & Al & 18.06  \% \\
Nitrogen & N & 8.423 \% \\
Osmium & Os & 0.00325 \% \\
\hline
\multicolumn{2}{c|}{} &\textbf{49.61025}   \% \\ \cline{3-3}
\end{tabular}
\end{center}

Please can someone help?

0

1 Answer 1

2

Four main suggestions:

  • Use \phantom{0} inserts in data rows 3 and 4 to achieve alignment on the decimal markers of the numbers in the preceding two rows.

  • Use a non-extended bold font face for the number in data row 5, so allow the digits to line up with the ones in the preceding rows. (Aside: if this were my table, I wouldn't bother bolding the number. Its stand-alone location suffices to give it a lot of visual prominence.)

  • Let LaTeX do the work of inserting the % symbol at the far right.

  • Use a centered version of the p column type to achieve an automatic line break in the "Measured Contribution" header cell.

enter image description here

\documentclass{article}
\usepackage{array}
\newcommand{\ubold}[1]{\fontseries{b}\selectfont#1}
\begin{document}
\begin{center}
\setlength\extrarowheight{2pt}
\begin{tabular}{|l|l|l@{\%\hspace{\tabcolsep}}|}
 \hline
\multicolumn{2}{|c|}{Element} &
\multicolumn{1}{>{\centering\arraybackslash}p{6em}|}{ Measured Contribution}\\
\hline
Magnesium & Mg & 23.124 \\
Aluminium & Al & 18.06   \\
Nitrogen  & N  & \phantom{0}8.423    \\
Osmium    & Os & \phantom{0}0.00325  \\
\hline
\multicolumn{2}{c|}{} & \ubold{49.61025} \\ 
\cline{3-3}
\end{tabular}
\end{center}
\end{document}
2
  • Thanks Mico could you give me an example on how to use the \phantom command as I have yet to use such a command Commented Apr 9, 2016 at 14:09
  • @user5438246 - In TeX jargon, a "phantom" is an invisible object that takes up some height and/or width. \phantom{0} takes up the width of its argument, but isn't visible. In the example, they serve to shift the remainder of the cell contents to the right, aligning them on the decimal marker in the process.
    – Mico
    Commented Apr 9, 2016 at 14:19

You must log in to answer this question.

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