1

This is probably a really simple question, but I don't know what keywords this question might have so I have trouble with searching it over the net. Anyway below is a code I wrote for a table.

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\centering
\small
\begin{tabular}{|c|c|c|}
\hline
\textbf{Sample} & \multicolumn{2}{c|}{\textbf{Excitation Wavelengths}} \\ \hline
Chl-a           & \SI{415}{\nano\meter}     & \SI{570}{\nano\meter}    \\ \hline
Pheo-a          & \SI{415}{\nano\meter}     & \SI{620}{\nano\meter}    \\ \hline
Zn-Pheo-a       & \SI{420}{\nano\meter}     & \SI{604}{\nano\meter}     \\ \hline
\end{tabular}
\end{table}
\end{document}

Which generates a table that looks like this: Table Genrated From Above Code Now what modification should I use to bring the 2nd column cell border to the center?

Thanks!

Vinsen
  • 87

1 Answers1

2

First of all, please read Why not use vertical lines ('|') in a tabular?

Now, a possible solution with X columns form tabularx package. The problem is that a certain tabular width must be fixed as a first parameter.

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{siunitx}
\usepackage{lipsum}
\usepackage{tabularx}

\begin{document}
\lipsum[1]
\begin{table}[h]
\centering
\small
\begin{tabularx}{.5\linewidth}{|c|>{\centering\arraybackslash}X|>{\centering\arraybackslash}X|}
\hline
\textbf{Sample} & \multicolumn{2}{c|}{\textbf{Excitation Wavelengths}} \\ \hline
Chl-a           & \SI{415}{\nano\meter}     & \SI{570}{\nano\meter}    \\ \hline
Pheo-a          & \SI{415}{\nano\meter}     & \SI{620}{\nano\meter}    \\ \hline
Zn-Pheo-a       & \SI{420}{\nano\meter}     & \SI{604}{\nano\meter}     \\ \hline
\end{tabularx}
\end{table}
\lipsum[1]
\end{document}

enter image description here

If you consider not to use vertical lines, an option could be:

enter image description here

which was done with

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{siunitx}
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
\lipsum[1]
\begin{table}[h]
\centering
\small
\begin{tabularx}{.5\linewidth}{c>{\centering\arraybackslash}X>{\centering\arraybackslash}X}
\toprule
&\multicolumn{2}{c}{\textbf{Excitation Wavelengths}} \\
\cmidrule{2-3}
\textbf{Sample} & $\lambda_1$ (\si{\nano\meter}) & $\lambda_2$ (\si{\nano\meter}) \\ \midrule
Chl-a           & 415     & 570 \\ 
Pheo-a          & 415     & 620 \\
Zn-Pheo-a       & 420     & 604 \\ 
\bottomrule
\end{tabularx}
\end{table}
\lipsum[1]
\end{document}
Ignasi
  • 136,588
  • Thanks, it seems that I still have a bunch to learn. Anyway, changing the documentclass into \documentclass[a4paper,10pt, twocolumn]{scrartcl} screws up the table. Any reason for this? @Ignasi – Vinsen May 22 '15 at 13:38
  • @Vinsen With twocolumn use \columnwidth instead of .5\linewidth. – Ignasi May 22 '15 at 13:48
  • @Vinsen: Some more lecture ;) http://tex.stackexchange.com/q/16942/1952 – Ignasi May 22 '15 at 13:51