just wanted to create a table, that looks something like the following
First and second row are no problem at all, but the third row is difficult. I can't achieve this special alignment.
Thanks in advance
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI guess the semi-tricky thing about the table is that whereas the columns' contents are all left-aligned, the numbers are -- depending on point of view -- either right-aligned or aligned on their decimal points/commas.
To achieve the desired look, you could use
the tabularx
package and a modified form of its X
column type to generate left-aligned entries while automatically breaking lines in the table's header, and
"phantoms" to insert whitespace where needed. Since three instances of such a need occur just on the third line, it's handy to create a shortcut macro for this task, e.g., to set \newcommand\ph{$\phantom{1}$}
.
\documentclass{article}
\usepackage{booktabs,tabularx}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcommand\ph{$\phantom{1}$} % a handy shortcut
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath} % looks like the font is use is "Times Roman"
\begin{document}
\noindent
\begin{tabularx}{0.6\textwidth}{@{} YYY @{}}
\toprule
\textbf{Wellenlänge} & \textbf{Spezifische Absorption} & \textbf{Maximale Abweichung}\\
\textbf{(nm)} & $\mathbf{A}^{1\,\%}_{1\,\text{cm}}$\\
\midrule
235 & 124,5 & 122,9 -- 126,2 \\
257 & 144,5 & 142,8 -- 146,2 \\
313 & \ph48,6 & \ph47,0 -- \ph50,3 \\
350 & 107,3 & 105,6 -- 109,0 \\
\bottomrule
\end{tabularx}
\end{document}
There are some ways to get this layout, one already proposed by Ian Thompson using \phantom
, also shown here or using extra columns with automatic filling of the -
characters in the 3rd logical column from the screen shot.
\documentclass[12pt]{article}
\usepackage{array}
\begin{document}
\begin{center}
\begin{tabular}{lrr}
\hline
\textbf{Wellenl\"ange} & \textbf{Spezifische} & \multicolumn{1}{l}{\textbf{Maximale}} \tabularnewline
& \textbf{Absorption} & \multicolumn{1}{l}{\textbf{Abweichung}} \tabularnewline
\textbf{(nm) } & & \tabularnewline
\hline
235 & 124,5 & 122,9 -- 126,2 \tabularnewline
257 & 144,5 & 142,8 -- 146,2 \tabularnewline
313 & 48,6 & \phantom{1}47,0 -- \phantom{1}50,3 \tabularnewline
350 & 107,3 & 105,6 -- 109,0 \tabularnewline
\hline
\end{tabular} \par
\end{center}
\begin{center}
\begin{tabular}{lrrl@{--}lr}
\hline
\textbf{Wellenl\"ange} & \textbf{Spezifische} & \multicolumn{4}{l}{\textbf{Maximale}} \tabularnewline
& \textbf{Absorption} & \multicolumn{4}{l}{\textbf{Abweichung}} \tabularnewline
\textbf{(nm) } & & \multicolumn{4}{l}{} \tabularnewline
\hline
235 & 124,5 & 122,9 & & & 126,2 \tabularnewline
257 & 144,5 & 142,8 & & & 146,2 \tabularnewline
313 & 48,6 & 47,0 & & & 50,3 \tabularnewline
350 & 107,3 & 105,6 & & & 109,0 \tabularnewline
\hline
\end{tabular}
\end{center}
\end{document}
\phantom{1}
to create an invisible digit1
.