表格中的文本对齐——右对齐、左对齐或居中对齐

表格中的文本对齐——右对齐、左对齐或居中对齐

我正在尝试对齐表格中的文本,但不知何故第一个带有年份 (1848) 的单元格未对齐。我该如何修复此问题?另一个问题是:如何指定是否要在不同的列 {ccc} 中将文本右对齐、左对齐或居中对齐。我如何指定列宽的大小?{r(2cm)}r(2cm)

以下是我的 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} 

答案1

这是使用包的示例threeparttable。您的对齐问题是由不可见规则引起的,我用命令替换了它\addlinespace。我调整了的值\defaultaddspace以获得与您的不可见规则相同的效果。

\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} 

在此处输入图片描述

答案2

问题是,支柱\rule{0cm}{0.30cm}应该位于\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}

\renewcommand{\arraystretch}{1.5}不过,请考虑移除所有支柱并使用(您可以使用 1.5)来\begin{table}控制行距的可能性。

至于如何对齐列,如果您希望列分别左对齐或右对齐,请使用{l}{r}代替。{c}

最后,关于控制可以使用的列宽{p{1cm}}(对于这种类型的列,文本的对齐方式与普通段落相同;如果需要左对齐、右对齐或居中对齐,请参见如何创建带有文本“raggedright/centered/raggedleft”的固定宽度表格列?

答案3

这是制作该表的一种简单方法。

在任何 LaTeX 表中,您都可以在序言中设置列的对齐方式,例如{rll}。要指定宽度,您可以使用p{\width}代表\width带单位的测量长度(4cm)或 LaTeX 变量长度(0.5\linewidth)。

tabularx包非常适合这个特定的表格,因为您可以指定前两列,然后使用一X列来获取填充剩余空间并根据需要换行文本的右列。

由于您已经在使用booktabs,它旨在通过其\toprule\midrule命令实现特定样式的表格,因此向表格添加其他规则可能不是最佳样式。您可以\addlinespacebooktabs包中查看。

该类book设计用于将标题放在表格下方;否则间距会不合适。 并且\tabularnewline不需要在普通表格中使用,只有\\

\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} 

在此处输入图片描述

答案4

您可以遵循以下详细的 bibtex 规范:14 种 BibTeX 条目类型

在此处输入图片描述

相关内容