0

I am trying to align the text in a table, but somehow the first cell with the year (1848) is not aligned. How can I fix this? Another question is: how can I specify if I want to align the text right, left, or centre in different columns {ccc}. How can I also specify the size of the column width? {r(2cm)}r(2cm)

Below is my WE:

  %---------------------Preamble---------------%
\documentclass[twoside,b5paper,9.5pt,openright]{book}
\usepackage[total={13cm,19.5cm},top=2.5cm,bottom=2.0cm,left=2.0cm,right=2.0cm, includefoot]{geometry} 
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{amsmath}
\usepackage{tocloft}
\usepackage{fixltx2e}
\usepackage{sectsty}
\usepackage[english]{babel}
\usepackage{microtype}          % removes extra spacing between text
\usepackage{chapterbib}
\pagenumbering{gobble}          % Remove page numbers in a section. The counting starts from Introduction
\usepackage{fancyhdr}           % fancy heading style in headers and footers
\usepackage{footnote}           % use with savenotes to show footnotes % footnotemark can be used when you have to use the same footnote twice (to avoid repetition)
\usepackage{graphicx}           % include graphs/ figures  in the file
\usepackage{setspace}           % to set the line spacing in the document
\usepackage{ragged2e}
\usepackage{lscape}             % to write pages in landscape environment
\usepackage{threeparttable}     % to add footnotes to the tables
\usepackage{booktabs}
\usepackage{caption}    % to create some space between table caption and table, otherwise there was no space
\captionsetup[table]{skip=5pt}
\usepackage[normalem]{ulem}     % to underline the text
\providecommand\phantomsection{}
\setcounter{secnumdepth}{3}
\usepackage{graphicx}
\usepackage[labelfont=bf]{caption}
\usepackage[font={small}]{caption}
\let\newfloat\relax
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\floatsetup[figure]{capposition=bottom}
\usepackage{etoolbox}
\usepackage{subfig}
\usepackage{xcolor}
\usepackage{grffile}            % to avoid printing the figure name (or otherwise, give figure names without spaces)
\usepackage{float}              % figures as 6 (a), 6 (b) etc.
\usepackage{tabu}
\usepackage{tikz}
\usepackage{arydshln}
\raggedbottom
\usepackage[compact]{titlesec}  
\usepackage[sort&compress]{natbib}
\usepackage{lipsum}
\usepackage{hyperref}
\setlength{\bibsep}{3.05pt}     % spacing between different references
\def\bibfont{\scriptsize}       % fontsize of the references
\usepackage[                    
singlelinecheck=false 
]{caption}

%---------------------Document starts here---------------%
\begin{document}            % the document starts here!

\begin{table}[h!]
\scriptsize
\centering
  \caption{Historical milestones in development of animal cell cultures (\cite{butler2004, verma2014})}
    \begin{tabular}{ccc}     \toprule
    \textbf{Timeline} & \textbf{Scientist} & \textbf{Achievements} \tabularnewline  
    \midrule
    1878  & Bernard & Physiological state of cells can be maintained after the death of an organism \tabularnewline      \rule{0cm}{0.30cm}
    1885  & Roux  & Maintained chick embryonic cells in warm salt solutions \tabularnewline      \rule{0cm}{0.30cm}
    1989  & Amgen Inc. & Recombinant erythropoietin produced in CHO cells \tabularnewline   
    \bottomrule
    \end{tabular}%
  \label{tab:history}%
\end{table}%

\end{document} 
abhishek
  • 465

4 Answers4

4

The problem is that the struts \rule{0cm}{0.30cm} should be before the \tabularnewline:

\documentclass{article}
\usepackage{booktabs}
\begin{document}            % the document starts here!

\begin{table}[h!]
\scriptsize
\centering
  \caption{Historical milestones in development of animal cell cultures (\cite{butler2004, verma2014})}
    \begin{tabular}{ccc}     \toprule
    \textbf{Timeline} & \textbf{Scientist} & \textbf{Achievements} \tabularnewline  
    \midrule
    1878  & Bernard & Physiological state of cells can be maintained after the death of an organism \rule{0cm}{0.30cm}\tabularnewline
    1885  & Roux  & Maintained chick embryonic cells in warm salt solutions \rule{0cm}{0.30cm}\tabularnewline      
    1989  & Amgen Inc. & Recombinant erythropoietin produced in CHO cells\rule{0cm}{0.30cm} \tabularnewline   
    \bottomrule
    \end{tabular}%
  \label{tab:history}%
\end{table}%
\end{document}

Consider though the possibility of removing all the struts and using \renewcommand{\arraystretch}{1.5} (where you can play with the 1.5) just after \begin{table} in order to control the row spacing.

As for how to align the column, use {l} or {r} instead of {c} if you want the columns left or right aligned, respectively.

Finally, about controlling the width of a column you can use {p{1cm}} (with this type of column the text is justified as in a normal paragraph; if you need left, right, or center alignment see How to create fixed width table columns with text raggedright/centered/raggedleft?)

summer
  • 1,474
4

Here is an example using the threeparttable package. You alignment problem was caused by the invisible rules, which I replaced with the \addlinespace command. I adjusted the value of \defaultaddspace so as to obtain the same effect as your invisible rules.

\documentclass[twoside,b5paper,9.5pt,openright]{book}
\usepackage[total={13cm,19.5cm},top=2.5cm,bottom=2.0cm,left=2.0cm,right=2.0cm, includefoot]{geometry}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{amsmath}
\usepackage{fixltx2e}
\usepackage[english]{babel}
\usepackage{microtype} % removes extra spacing between text
\pagenumbering{gobble} % Remove page numbers in a section. The counting starts from Introduction
\usepackage{ragged2e}
%\usepackage{lscape} % to write pages in landscape environment
\usepackage{array, threeparttable} % to add footnotes to the tables
\usepackage{booktabs}
\usepackage{caption} % to create some space between table caption and table, otherwise there was no space
\captionsetup[table]{skip=5pt}
\usepackage[singlelinecheck=false]{caption}

\setlength\defaultaddspace{0.66ex}
%---------------------Document starts here---------------%
\begin{document} % the document starts here!

\begin{table}[h!]
\scriptsize
\captionsetup{font=small}
\setlength\defaultaddspace{0.66ex}
\centering
\begin{threeparttable}
  \caption{Historical milestones in development of animal cell cultures (\cite{butler2004, verma2014})}
  \label{tab:history}%
    \begin{tabular}{@{}ccm{5cm}@{}}
    \toprule
    \textbf{Timeline} & \textbf{Scientist} & \textbf{Achievements} \tabularnewline
    \midrule
    1878 & Bernard & Physiological state of cells can be maintained after the death of an organism \tabularnewline
\addlinespace
    1885 & Roux & Maintained chick embryonic cells in warm salt solutions \tabularnewline
\addlinespace
    1989 & Amgen Inc. & Recombinant erythropoietin produced in CHO cells \tabularnewline
    \bottomrule
    \end{tabular}%
\end{threeparttable}
\end{table}%

\end{document} 

enter image description here

Bernard
  • 271,350
  • your solution works nicely, as I do not have to change a lot in the existing table. But, If I want to have different line spacing in different tables, how can I define that option? – abhishek Mar 20 '15 at 21:26
  • You have different solutions: first you can change locally the value of \defauladdspace. However this requires writing \addspace between each row. You also can use the cellspace package, which ensures a minimal vertical spacing between a cell and the above and below cells. A thirs solution is the makecell package, which allows to add a fixed height and depth to all cells in a table. See the documentation of these packages for details. – Bernard Mar 20 '15 at 21:41
  • I am having difficulties with defining \defaultaddspace locally. can you provide an example please? thanks – abhishek Mar 21 '15 at 19:20
  • For instance you can move it inside the table or the threeparttable environment, but before tabular (where it is used). See my modified answer. If you don't have any environment inside which to put it, enclose it within a pair of braces. – Bernard Mar 21 '15 at 19:34
2

Here is a simple way you can make this table.

In any LaTeX table, you set the alignment of the columns in the preamble, e.g., {rll}. To specify the width you can use p{\width} where \width stands for either a measured length with unit (4cm) or a LaTeX variable length (0.5\linewidth).

The tabularx package is ideal for this particular table, because you can specify the first two columns and then use an X column to get a right column that fills the remaining space and wraps the text as needed.

Since you are already using booktabs, which is designed to implement a specific style of tables with its \toprule and \midrule commands, it is probably not the best style to add additional rules to the table. You might look at \addlinespace from the booktabs package.

The book class is designed for captions to be placed underneath tables; otherwise the spacing is off. And \tabularnewline is not needed in normal tables, only \\.

\documentclass{book}
\usepackage{booktabs,tabularx}

\begin{document}

\begin{table}
\begin{tabularx}{\linewidth}{r l X}
\toprule
Timeline & Scientist & Achievements\\
\midrule
1878  & Bernard & Physiological state of cells can be maintained after the death of an organism\\
1885  & Roux  & Maintained chick embryonic cells in warm salt solutions\\
1989  & Amgen Inc. & Recombinant erythropoietin produced in CHO cells\\
\bottomrule
\end{tabularx}
\caption{Historical milestones in development of animal cell cultures}
\label{tab:history}
\end{table}

\end{document} 

enter image description here

musarithmia
  • 12,463
  • The spacing for captions above the table could be controlled though with \usepackage{caption}\captionsetup{aboveskip=3pt} – summer Mar 20 '15 at 19:18
  • @summer Thanks - the Chicago Manual of Style, for one, recommends table captions above the table, so what you suggest would be better. – musarithmia Mar 20 '15 at 20:07
  • @AndrewCashner I have this code in my preamble to place the captions on the top of the table: \let\newfloat\relax \usepackage{floatrow} \floatsetup[table]{capposition=top} – abhishek Mar 21 '15 at 01:29
  • @musarithmia Can you please tell how to use p{\width} along with {r l l}. I used the following line: \begin{tabularx}{p{3cm} p{3.5cm} p{7cm}}{c c X}. I am getting error. Basically I want to have a table with three columns, with each column having different width and different alignment. Can you please help me? – Aim Mar 27 '20 at 11:10
  • @Giri With tabularx or tabulary the first argument is the maximum width of the table, then the specifications for the columns. So, \begin{tabularx}{\textwidth}{ p{1in} c X } would produce a table as wide as the text block where the first column is formatted like a regular paragraph, 1 inch wide; the second column is centered and is as wide as the content of that column, and the third column X fills the remaining width and is formatted like a regular paragraph. – musarithmia Mar 31 '20 at 14:19
  • @Giri You use p{1in} in place of l, c, or r to specify the width. Try texdoc latex2e and look up tabular, or check the LaTeX Wikibook. Post a new question on this site if you still have a specific question and we will help! – musarithmia Mar 31 '20 at 14:21
0

You can follow the bibtex specifications as detailed here: The 14 BibTeX entry types.

enter image description here

MarianD
  • 145