表格中的文本间距和对齐方式

表格中的文本间距和对齐方式

我使用下面的代码制作了一个表格,但存在以下一些问题:

  1. 标题未居中对齐
  2. 每行的文本不从同一点开始
  3. 文本之间的间距太大。见下图:

在此处输入图片描述

这是我的代码。

\documentclass[a4paper,11pt,fleqn]{report}
\usepackage[margin=30mm]{geometry}
\usepackage{array}

\begin{document}
    \begin{table}[h!]
        \setlength\extrarowheight{2pt}
        \begin{center}
            \renewcommand{\arraystretch}{1.0}
            \tabcolsep=0.11cm
            \begin{tabular}{m{0.15\linewidth}m{0.2\linewidth}m{0.2\linewidth}m{0.2\linewidth}m{0.2\linewidth}}
                \hline 
                \textbf{Stakeholder} & \textbf{Travel Time} & \textbf{Service Frequency} & \textbf{Accessibility} & \textbf{Operating Cost}\\ 
                \hline
                \textbf{User} & Prefers the most direct routes, in order to reduce travel time & Prefers high frequency service with little or no waiting time &Prefers high proximity and access to the infrastructure like stops and stations to their desired origins and destinations. & Desires the cheapest fare possible for each trip. \\ 
                \textbf{Operator} & Prefers to operate indirect routes, in order to maximize patronage. & Will offer service frequencies that will ensure a maximum utilization of resources and least operational cost. & Prefers central locations where more passengers can access the service irrespective of distance to individual origins and destinations & Desires competitive and profitable fares. \\ 
                \textbf{Agency} & Prefers a travel time that is in line with the agency’s policy. & Prefers service frequencies that reflects the strategic transit goal of the government. & Prefers infrastructure coverage that satisfies most of the community. & Willing to subsidize fares, in order to make it affordable for users and profitable for operators. \\  
                \hline 
            \end{tabular} 
            \caption{Different travel stakeholders and their perceived objectives \label{[Tab1.3:Expanded form of table one whowing more modes and their attributes]}}
        \end{center}
    \end{table}
\end{document}

答案1

您的tabular环境不能保证适合文本块的宽度。(事实上,它有点太宽了。)我建议改用环境tabualarx。我还建议使用包的线条绘制宏,booktabs而不是使用\hline

在此处输入图片描述

\documentclass[a4paper,11pt,fleqn,english]{report}
\usepackage[margin=30mm]{geometry}
\usepackage{tabularx,ragged2e,booktabs,babel}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X} % for columns 2 thru 5
\newcolumntype{C}{>{\Centering\bfseries\arraybackslash}X} % for header cells
\newcommand\mc[1]{\multicolumn{1}{@{}C@{}}{#1}}
\hyphenation{infra-structure}
\begin{document}
    \begin{table}[h!]
        \setlength{\tabcolsep}{3pt} % default value: 6pt
        \begin{tabularx}{\textwidth}{@{} l *{4}{Y} @{}}
        \toprule
        \textbf{Stakeholder} &
        \mc{Travel Time} & \mc{Service Frequency} &
        \mc{Accessibility} & \mc{Operating Cost} 
        \\
        \midrule
        \textbf{User} & Prefers the most direct routes, in order to reduce travel time & Prefers high frequency service with little or no waiting time &Prefers high proximity and access to the infrastructure like stops and stations to their desired origins and destinations. & Desires cheapest fare possible for each trip. \\
        \addlinespace
        \textbf{Operator} & Prefers to operate indirect routes, in order to maximize patronage. & Will offer service frequencies that will ensure a maximum utilization of resources and least operational cost. & Prefers central locations where more passengers can access the service irrespective of distance to individual origins and destinations. & Desires competitive and profitable fares. \\
        \addlinespace
        \textbf{Agency} & Prefers a travel time that is in line with the agency’s policy. & Prefers service frequencies that reflects the strategic transit goal of the government. & Prefers infrastructure coverage that satisfies most of the community. & Willing to subsidize fares, in order to make it affordable for users and profitable for operators. \\
        \bottomrule
        \end{tabularx}
        \caption{Different travel stakeholders and their perceived objectives} 
        \label{Tab1.3} % there's no point in having an overly long \label
    \end{table}
\end{document} 

答案2

这里有一个。但是,我还是建议重写它(没有关于如何重写的建议),因为它看起来不会很好看,读起来也不会很舒服。

\documentclass[a4paper,11pt,fleqn]{report}
\usepackage[margin=30mm]{geometry}
\usepackage{array,ragged2e}

\begin{document}
    \begin{table}[h!]
        \setlength\extrarowheight{2pt}
        \begin{center}
            \renewcommand{\arraystretch}{1.0}
            \tabcolsep=0.11cm
            \begin{tabular}{ 
                >{\RaggedRight\arraybackslash} m{0.15\linewidth}
                >{\RaggedRight\arraybackslash} m{0.2\linewidth}
                >{\RaggedRight\arraybackslash} m{0.2\linewidth}
                >{\RaggedRight\arraybackslash} m{0.2\linewidth}
                >{\RaggedRight\arraybackslash} m{0.2\linewidth}
              }
                \hline 
                \Centering \textbf{Stakeholder} 
                & 
                \Centering\textbf{Travel Time} 
                & 
                \Centering \textbf{Service Frequency} 
                & 
                \Centering \textbf{Accessibility} 
                & 
                \Centering \textbf{Operating Cost}
                \\ 
                \hline
                \textbf{User} & Prefers the most direct routes, in order to reduce travel time & Prefers high frequency service with little or no waiting time &Prefers high proximity and access to the infrastructure like stops and stations to their desired origins and destinations. & Desires the cheapest fare possible for each trip. \\ 
                \textbf{Operator} & Prefers to operate indirect routes, in order to maximize patronage. & Will offer service frequencies that will ensure a maximum utilization of resources and least operational cost. & Prefers central locations where more passengers can access the service irrespective of distance to individual origins and destinations & Desires competitive and profitable fares. \\ 
                \textbf{Agency} & Prefers a travel time that is in line with the agency’s policy. & Prefers service frequencies that reflects the strategic transit goal of the government. & Prefers infrastructure coverage that satisfies most of the community. & Willing to subsidize fares, in order to make it affordable for users and profitable for operators. \\  
                \hline 
            \end{tabular} 
            \caption{Different travel stakeholders and their perceived objectives \label{[Tab1.3:Expanded form of table one whowing more modes and their attributes]}}
        \end{center}
    \end{table}
\end{document}

答案3

考虑来自booktabs包+的所有评论+添加的规则theadmakecell

编辑: 并考虑米科关于表格宽度的评论。这可以通过使用tabularx表格环境简单地完成,如下所示:

在此处输入图片描述

\documentclass[a4paper,11pt,fleqn]{report}
\usepackage[margin=30mm]{geometry}
\usepackage{ragged2e}
\usepackage{array, booktabs, makecell, tabularx}
\renewcommand\theadfont{\bfseries\small}

\usepackage{lipsum}

\begin{document}
\lipsum[11] % for see the text width
    \begin{table}[h!]
    \centering
\begin{tabular}{@{}>{\bfseries} l
                *{4}{>{\RaggedRight}X}
                @{}}
    \toprule
\thead[b]{Stake\-\\holder} & \thead[b]{Travel Time} & \thead[b]{Service\\ Frequency} & \thead[b]{Accessibility} & \thead[b]{Operating Cost}\\
    \midrule
User        & Prefers the most direct routes, in order to reduce travel time & Prefers high frequency service with little or no waiting time &Prefers high proximity and access to the infrastructure like stops and stations to their desired origins and destinations. & Desires the cheapest fare possible for each trip. \\
    \addlinespace
Operator    & Prefers to operate indirect routes, in order to maximize patronage. & Will offer service frequencies that will ensure a maximum utilization of resources and least operational cost. & Prefers central locations where more passengers can access the service irrespective of distance to individual origins and destinations & Desires competitive and profitable fares. \\
    \addlinespace
Agency  & Prefers a travel time that is in line with the agency’s policy. & Prefers service frequencies that reflects the strategic transit goal of the government. & Prefers infrastructure coverage that satisfies most of the community. & Willing to subsidize fares, in order to make it affordable for users and profitable for operators. \\
    \bottomrule
\end{tabular}
    \caption{Different travel stakeholders and their perceived objectives
\label{[Tab1.3:Expanded form of table one whowing more modes and their attributes]}}
    \end{table}

相关内容