1
\documentclass[11pt]{article}  

\usepackage{geometry}                       
\geometry{a4paper}   
\usepackage{mathpazo} 
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\begin{table}[htdp]

\centering
\caption{Absorbances of samples of different Concentrations\label{mytable}}
\begin{tabular}{lll} 
\toprule
Sample & Concentration \linebreak (mg/L) & Absorbance at \linebreak $\lambda_{max}$ \\ 
\midrule
blank  & 0.0000   & 0.000 \\                                                                   
a      & 0.2849   & 0.059 \\                                                                   
b      & 0.7122   & 0.160 \\                                                                
c      & 1.424    & 0.311 \\                                                                
d      & 2.137    & 0.468 \\                                                                  
e      & 2.849    & 0.608 \\ 
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

Why don't my \linebreaks work?

EDIT: I tried to change the code to a two column table

\documentclass[11pt]{article}  
\newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}} 
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}
\begin{table}       
    \centering
    \caption{Absorbances of 20 \si{\ml} sample at different Wavelengths}
    \label{mytable}
    \begin{tabular}{lS[table-format=1.3]} 
        \toprule
        {\specialcell[t]{Wavelength \\in \si{\nano\meter}}}  & Absorbance   \\ 
        \midrule
        400      & 0.240  \\                                                                   
        425      & 0.382  \\                                                                   
        450       & 0.486  \\                                                                
        475      & 0.574  \\                                                                
        500      & 0.608  \\                                                                  
        505      & 0.608 \\
        510      & 0.602 \\ 
        525      & 0.508 \\
        \bottomrule
    \end{tabular}
\end{table} 
\end{document}  

enter image description here

But it throws and error when I add an 'e' to Absorbance

Jack
  • 259
  • Too broad question (vote to close). Please ask about specif problems that you have. Improve a text is a endless/subjective task. IMHO a major improvement could be avoid the tables that look like a spreadsheet. Use centered tables with only 3 horizontal rules. Search in this site about the booktabs package to see nice examples. – Fran Nov 10 '14 at 06:07
  • @Fran I tried to fix the table but I cant get the titles to be centred? – Jack Nov 10 '14 at 06:46
  • Use \caption{My caption\label{mytable}} before the tabular environment, but inside the table environment. – Fran Nov 10 '14 at 06:56
  • See http://tex.stackexchange.com/questions/2746/aligning-numbers-by-decimal-points-in-table-columns – Fran Nov 10 '14 at 07:00
  • Thanks :) Just one more thing. Do you know why my line breaks dont seem to work? – Jack Nov 10 '14 at 07:01
  • Please add new question with minimal working example (MWE) that illustrates your problem with pagebreaks. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}... but as short as possible. – Fran Nov 10 '14 at 07:19
  • @Fran Done. Btw it's starting to look so much nicer than when I started! – Jack Nov 10 '14 at 07:28
  • Related: http://tex.stackexchange.com/q/485 – LaRiFaRi Nov 10 '14 at 08:46

1 Answers1

2

\linebreak is not a command which is meant for tables. You will have to use a p column here or you define a table for each cell. In this answer it has been shown nicely, how to define a command for that.

% arara: pdflatex

\documentclass[11pt,a4paper]{article}     
\usepackage{mathpazo} 
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{caption}
\newcommand{\specialcell}[2][c]{%
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}} % replace c bei l if you want the text to appear ragged right (flush left)
\usepackage{siunitx}

\begin{document}    
    \begin{table}       
        \centering
        \caption{Absorbances of samples of different Concentrations}
        \label{mytable}
        \begin{tabular}{lS[table-format=1.4]S[table-format=1.3]} 
            \toprule
            Sample & {\specialcell[t]{Concentration\\in \si{\milli\gram\per\liter}}} & {\specialcell[t]{Absorbance at\\$\lambda_\text{max}$}} \\ 
            \midrule
            blank  & 0.0000   & 0.000 \\                                                                   
            a      & 0.2849   & 0.059 \\                                                                   
            b      & 0.7122   & 0.160 \\                                                                
            c      & 1.424    & 0.311 \\                                                                
            d      & 2.137    & 0.468 \\                                                                  
            e      & 2.849    & 0.608 \\ 
            \bottomrule
        \end{tabular}
    \end{table} 
\end{document}

enter image description here

LaRiFaRi
  • 43,807
  • Thanks. I tried to make a different table with only two columns. I'm not sure how to change \begin{tabular}{lS[table-format=1.4]S[table-format=1.3]} I tried to read through the documentation at http://www.tug.org/pracjourn/2007-1/mori/mori.pdf but CTRL+F "table-format" did not show anything – Jack Nov 10 '14 at 19:21
  • Here's what the two column table looks like http://imgur.com/iNkYHyP – Jack Nov 10 '14 at 19:24
  • @Jack Hi, please do not add external links here but ask new questions with code. Or search this site for solutions. I can't open your last link here, but for your question: You will have to read the manual of [tag:siunitx] in order to find table-format. In short: S is a column type for decimal-point-aligned numbers and 1.4 means 1 digit before and 4 digits after the dot. For a two columns table, you will have to decide, if you need left l, right r, center c, or decimal-point S aligned columns. – LaRiFaRi Nov 11 '14 at 09:18