表格宽度和标题

表格宽度和标题

我想创建一个表: 在此处输入图片描述

这是一个大小和样式都很复杂的表格:我尝试了以下代码:

\documentclass{article}

\usepackage{booktabs}

\begin{document}
\begin{table}
    \begin{tabular}{|l|lll|ll|l|ll|}
    \hline
     Name   of bus stop         & Number of passengers & ~     & ~          & ~      & ~     & Growth in Bike-and-ride users (\%) & Share of bike-and-ride users & ~     \\
    ~                           & Before               & After & Growth (\%) & Before & After & ~                                 & Before                       & After \\ \hline
    Zevenbergen-Drie Hoefijzers & 28                   & 28    & 0          & 23     & 18    & -18                               & 82                           & 65    \\
    Oosterhout-Europaweg        & 32                   & 47    & 47         & 4      & 14    & 250                               & 13                           & 30    \\
    Oosterhout-Napoleonlaan     & 195                  & 211   & 8          & 10     & 17    & 90                                & 5                            & 8     \\
    Oosterhout-Elkhuizenlaan    & 127                  & 123   & -3         & 14     & 27    & 80                                & 11                           & 22    \\
    Oosterhout-Busstation       & 409                  & 647   & 58         & ~      & 220   & 35                                & 41                           & 34    \\
    Werkendam-Sleewijk          & 129                  & 184   & 43         & 92     & 127   & 32                                & 71                           & 69    \\
    Raamsdonkveer Busstation    & 448                  & ~     & ~          & ~      & ~     & ~                                 & ~                            & ~     \\
    Total                       & 1368                 & 1718  & 26         & 520    & 618   & 20                                & 38                           & 36    \\ \hline
    \end{tabular}
\end{table}
\end{document}

结果创建一个不同的表:

在此处输入图片描述

答案1

这是一个入门指南。研究一下代码。我不能保证它完全按照你的要求进行了优化,但它可以帮助你实现目标:

\documentclass{article}
\usepackage{booktabs,multirow}% http://ctan.org/pkg/{booktabs,multirow}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
\makebox[\linewidth]{%
\begin{tabular}{|p{3.5cm}|l|l|l|l|l|p{2cm}|l|l|}
\hline
Name of bus stop & \multicolumn{3}{l|}{Number of Passengers} & \multicolumn{2}{p{2.5cm}|}{Number of bike-and-ride users} & Growth in Bike-and-ride users (\%) & \multicolumn{2}{p{2.5cm}|}{Share of bike-and-ride users}\\ \cline{2-6}\cline{8-9}
& Before & After & Growth (\%) & Before & After && Before & After\\ \hline
Zevenbergen-Drie Hoefijzers & 28  & 28    & 0  & 23  & 18  & -18   & 82   & 65    \\
\hline
\end{tabular}%
}
\end{document}

在此处输入图片描述

答案2

一个复杂的表格,但使用完美构建卡路里

\documentclass[a4paper]{article}
\usepackage{cals}
\usepackage[margin=2cm]{geometry}
\thispagestyle{empty}

    % Shortcuts
\let\nc=\nullcell
\let\sc=\spancontent

\newcommand{\qem}{\rule{0.25em}{0pt}}

\begin{document}

\small   
\begin{calstable}[c]
\colwidths{{\dimexpr(\columnwidth)/120*14+4pt\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*10\relax}
                  {\dimexpr(\columnwidth)/120*8-2pt\relax} % Fine tuning to avoid overfull hbox
                  {\dimexpr(\columnwidth)/120*8-2pt\relax}
                  {\dimexpr(\columnwidth)/120*10\relax} 
                  {\dimexpr(\columnwidth)/120*10\relax}
        }
\makeatletter
\def\cals@framers@width{0.8pt}
\def\cals@framecs@width{0.4pt}


%
\thead{\bfseries
\brow
    \nc{lt}
    \nc{t}
    \nc{rt}
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignC\sc{Number of passengers}
    \nc{ltb}
    \nc{rtb}\alignC\sc{Number of bike-and-ride users}
    \nc{lt}
    \nc{rt}
    \nc{ltb}
    \nc{rtb}\alignC\sc{\bfseries Share of bike-and-ride users}
\erow
%
\mdseries
\brow
    \nc{lb}
    \nc{b}
    \nc{rb}\alignC\sc{\bfseries Name   of bus stop}
    \cell{Before}
    \cell{After}
    \cell{Growth (\%)}
    \cell{Before}
    \cell{After}
    \nc{lb}
    \nc{rb}\alignC\sc{\bfseries Growth in Bike-and-ride users (\%)}
    \cell{Before (\%)}
    \cell{After (\%)}
\erow
}

%
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Zevenbergen-Drie Hoefijzers}
    \alignR\cell{28\qem}
    \alignR\cell{28\qem}
    \alignR\cell{0\qem}
    \alignR\cell{23\qem}
    \alignR\cell{18\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{$-$18\qem}
    \alignR\cell{82\qem}
    \alignR\cell{65\qem}
\erow
%
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Oosterhout-Europaweg}
    \alignR\cell{32\qem}
    \alignR\cell{47\qem}
    \alignR\cell{47\qem}
    \alignR\cell{4\qem}
    \alignR\cell{14\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{250\qem}
    \alignR\cell{13\qem}
    \alignR\cell{30\qem}
\erow
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Oosterhout-Napoleonlaan }
    \alignR\cell{195\qem}
    \alignR\cell{211\qem}
    \alignR\cell{8\qem}
    \alignR\cell{10\qem}
    \alignR\cell{17\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{90\qem}
    \alignR\cell{5\qem}
    \alignR\cell{8\qem}
\erow
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Oosterhout-Elkhuizenlaan}
    \alignR\cell{127\qem}
    \alignR\cell{123\qem}
    \alignR\cell{$-$3\qem}
    \alignR\cell{14\qem}
    \alignR\cell{27\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{80\qem}
    \alignR\cell{11\qem}
    \alignR\cell{22\qem}
\erow
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Oosterhout-Busstation}
    \alignR\cell{409\qem}
    \alignR\cell{647\qem}
    \alignR\cell{58\qem}
    \cell{~}
    \alignR\cell{220\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{35\qem}
    \alignR\cell{41\qem}
    \alignR\cell{34\qem}
\erow
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Werkendam-Sleewijk}
    \alignR\cell{129\qem}
    \alignR\cell{184\qem}
    \alignR\cell{43\qem}
    \alignR\cell{92\qem}
    \alignR\cell{127\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{32\qem}
    \alignR\cell{71\qem}
    \alignR\cell{69\qem}
\erow
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Raamsdonkveer Busstation}
    \alignR\cell{448\qem}
    \cell{~}
    \cell{~}
    \cell{~}
    \cell{~}
    \nc{ltb}
    \nc{rtb}\sc{~}
    \cell{~}
    \cell{~}
\erow
\brow
    \nc{ltb}
    \nc{tb}
    \nc{rtb}\alignL\sc{\bfseries Total}
    \alignR\cell{1368\qem}
    \alignR\cell{1718\qem}
    \alignR\cell{26\qem}
    \alignR\cell{520\qem}
    \alignR\cell{618\qem}
    \nc{ltb}
    \nc{rtb}\alignR\sc{20\qem}
    \alignR\cell{38\qem}
    \alignR\cell{36\qem}
\erow
\makeatother
\end{calstable}\par

\end{document}

在此处输入图片描述

相关内容