如何在 LaTeX 中连接两个表的边缘?

如何在 LaTeX 中连接两个表的边缘?

我想连接两个表的两个边缘,使表并排,即表 A 边缘在右,表 B 边缘在左。我知道线程我怎样才能让两张桌子并排?但我想特别连接边缘,即它们接触并共享一个共同的粗体边缘。代码及其输出如图 1 所示

\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=0pt]{geometry}% http://ctan.org/pkg/geometry

\begin{document}

    % https://en.wikibooks.org/wiki/LaTeX/Tables
    \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \\
    \hline
    \end{tabular}

    \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \\
    \hline
    \end{tabular}

\end{document}

图 1 输出

在此处输入图片描述

预期输出:同一行的两个表,其公共墙/边缘以粗体显示,作为清晰的分隔符

另一个示例是 1x3,包含 4 个表

显示 1x3 表结构,即左侧有一个表,右侧有三个表,因此有许多共同边。代码及其输出如图 2 所示

\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=0pt]{geometry}% http://ctan.org/pkg/geometry

\begin{document}

    \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \\
    \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \\
    \hline
    \end{tabular}

    \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    \end{tabular}

    \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    \end{tabular}

    \begin{tabular}{ | l | l | l | p{3cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    \end{tabular}

\end{document}

图 2 包含 4 个表的 1x3 表结构的输出

在此处输入图片描述

预期输出:1x3 表结构,其中 4 个表

使用 1x3 结构测试 Heiko 的方法

图 3 中最后一张表错误地显示在左侧的代码

\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=0pt]{geometry}% http://ctan.org/pkg/geometry

\usepackage{microtype}% more flexibility for narrow columns
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}

\newcommand*{\MakeCell}[1]{%
  \begingroup
    \renewcommand*{\arraystretch}{1}% reset if changed
    \begin{tabular}[b]{@{}c@{}}%
    #1%
    \end{tabular}%
  \endgroup
}

\begin{document}

\noindent
    \begin{tabularx}{.50\linewidth}[t]{ | l | l | l | X | }
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \\
    \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning.
    Conditions will improve by early afternoon and continue
    throughout the evening. \\
    \hline
    \end{tabularx}%
\kern-.2pt %
\vrule % default width is 0.4 pt
\kern-.2pt %
    \begin{tabularx}{.50\linewidth}[t]{ | l | l | l | X | }
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    \end{tabularx}
\kern-.2pt %
\vrule % default width is 0.4 pt
\kern-.2pt %
    \begin{tabularx}{.50\linewidth}[t]{ | l | l | l | X | }
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    \end{tabularx}
\kern-.2pt %
\vrule % default width is 0.4 pt
\kern-.2pt %
    \begin{tabularx}{.50\linewidth}[t]{ | l | l | l | X | }
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    \end{tabularx}  
\kern-.2pt %
\vrule % default width is 0.4 pt
\kern-.2pt %
    \begin{tabularx}{.50\linewidth}[t]{ | l | l | l | X | }
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
    across most of Scotland and Northern Ireland,
    but rain reaching the far northwest. \\ \hline
    \end{tabularx}  
    % TODO why this last is wrongly put to the left-hand-side

\end{document}

图 3 中的输出错误地显示了左侧的最后一个表格

图 3 输出

在此处输入图片描述

操作系统:Debian 9
TeXLive:2017

答案1

两个表格并排的变体:

  • 为列tabularx包装环境,以最大化带有摘要的列的位置。tabularxX

  • 包装更美观booktabs

  • 带包装的单位siunitx

  • ...

示例文件:

\documentclass{article}
\usepackage{microtype}% more flexibility for narrow columns
\usepackage[english]{babel}
\usepackage[margin=0pt]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}

\newcommand*{\MakeCell}[1]{%
  \begingroup
    \renewcommand*{\arraystretch}{1}% reset if changed
    \begin{tabular}[b]{@{}c@{}}%
    #1%
    \end{tabular}%
  \endgroup
}

\begin{document}

    \noindent
    \begin{tabularx}{.49\linewidth}[t]{ l l l X }
    \toprule
    Day & \MakeCell{Min.\\temp.} & \MakeCell{Max.\\temp.} & Summary \\
    \midrule
    Monday & \SI{11}{\celsius} & \SI{22}{\celsius}
    & A clear day with lots of sunshine.
      However, the strong breeze will bring down the temperatures. \\
    \addlinespace
    Tuesday & \SI{9}{\celsius} & \SI{19}{\celsius}
    & Cloudy with rain, across many northern
      regions. Clear spells
      across most of Scotland and Northern Ireland,
      but rain reaching the far northwest. \\
    \addlinespace
    Wednesday & \SI{10}{\celsius} & \SI{21}{\celsius}
    & Rain will still linger for the morning.
      Conditions will improve by early afternoon and continue
      throughout the evening. \\
    \bottomrule
    \end{tabularx}%
    \hfill
    \begin{tabularx}{.49\linewidth}[t]{ l l l X }
    \toprule
    Day & \MakeCell{Min.\\temp.} & \MakeCell{Max.\\temp.} & Summary \\
    \midrule
    Monday & \SI{11}{\celsius} & \SI{22}{\celsius}
    & A clear day with lots of sunshine.
      However, the strong breeze will bring down the temperatures. \\
    \addlinespace
    Tuesday & \SI{9}{\celsius} & \SI{19}{\celsius}
    & Cloudy with rain, across many northern
      regions. Clear spells
      across most of Scotland and Northern Ireland,
      but rain reaching the far northwest. \\
    \addlinespace
    Wednesday & \SI{10}{\celsius} & \SI{21}{\celsius}
    & Rain will still linger for the morning.
      Conditions will improve by early afternoon and continue
      throughout the evening. \\
    \bottomrule
    \end{tabularx}

\end{document}

结果

使用垂直线而不是填充来分隔表格:

\end{tabularx}%
\kern-.2pt %
\vrule % default width is 0.4 pt
\kern-.2pt %
\begin{tabularx}{.5\linewidth}[t]{ l l l X }

垂直线结果

左侧有一张大桌子,右侧有三张小桌子的变体:

\documentclass{article}
\usepackage{xcolor}
\begin{document}

\newcommand*{\TableA}{%
  \textcolor{gray}{\rule{.5\linewidth}{10cm}}%
}
\newcommand*{\TableB}{%
  \textcolor{red}{\rule{.5\linewidth}{3cm}}%
}
\newcommand*{\TableC}{%
  \textcolor{green}{\rule{.5\linewidth}{3cm}}%
}
\newcommand*{\TableD}{%
  \textcolor{blue}{\rule{.5\linewidth}{3cm}}%
}
\sbox0{\TableA}%
\noindent
\vtop{%
  \kern0pt % Align at the top
  \copy0 %
}%
\kern-.2pt %
\vrule
\kern-.2pt %
\vtop to \dimexpr\ht0+\dp0{%
  \kern0pt % Align at the top
  \hbox{\TableB}%
  \vfill
  \hbox{\TableC}%
  \vfill
  \hbox{\TableD}%
}
\end{document}

结果

其他变体:

\documentclass{article}
\usepackage{xcolor}
\begin{document}

\newcommand*{\TableA}{%
  \textcolor{gray}{\rule{.5\linewidth}{10cm}}%
}
\newcommand*{\TableB}{%
  \textcolor{red}{\rule{.5\linewidth}{3cm}}%
}
\newcommand*{\TableC}{%
  \textcolor{green}{\rule{.5\linewidth}{3cm}}%
}
\newcommand*{\TableD}{%
  \textcolor{blue}{\rule{.5\linewidth}{3cm}}%
}
\noindent
\vtop{%
  \kern0pt % Align at the top
  \hbox{\TableA}%
}%
\kern-.2pt %
\vrule
\kern-.2pt %
\vtop{%
  \kern0pt % Align at the top
  \hbox{\TableB}%
  \nointerlineskip
  \hbox{\TableC}%
  \nointerlineskip
  \hbox{\TableD}%
}
\end{document}

结果

相关内容