\documentclass[12pt,a4size]{article}
\usepackage{showframe}
\usepackage{fancybox}
\usepackage{tabularx}
\begin{document}
\begin{table}[ht!]
\begin{minipage}{0.45\textwidth}
\begin{tabular}{|c|c|c|c|c|}
\hline
$\wedge$ &$\phi$ &$\{a\}$ &$\{b\}$ &$\{a,b\}$\\
\hline
$\phi$ & $\phi$ &$\phi$ &$\phi$ &$\phi$\\
\hline
$a$ &$\phi$ &\{a\} &$\phi$ &$\{a\}$\\
\hline
$b$ &$\phi$ &$\phi$ &$\{b\}$ &$\{b\}$ \\
\hline
$\{a,b\}$ &$\phi$ &$\{a\}$ &$\{b\}$ &$\{a,b\}$ \\
\hline
\end{tabular}
\caption{Composition table for meet}
\end{minipage}%
\begin{minipage}{0.45\textwidth}
\begin{tabular}{|c|c|c|c|c|}
\hline
$\vee$ &$\phi$ &$\{a\}$ &$\{b\}$ &$\{a,b\}$\\
\hline
$\phi$ & $\phi$ &$\{a\}$ &$\{b\}$ &$\{a,b\}$\\
\hline
$a$ &$\{a\}$ &$\{a\}$ &$\{a,b\}$ &$\{a,b\}$\\
\hline
$b$ &$\{b\}$ &$\{a,b\}$ &$\{b\}$ &$\{a,b\}$ \\
\hline
$\{a,b\}$ &$\{a,b\}$ &$\{a,b\}$ &$\{a,b\}$ &$\{a,b\}$ \\
\hline
\end{tabular}
\caption{Composition table for join}
\end{minipage}
\end{table}
\end{document}
我用过,begin{center}...\end{center}
但这会把表格垂直放置,我不想要。糟糕的盒子评论是Overfull \hbox (4.24258pt too wide) in paragraph
答案1
@leandriis 答案的一个小变化(+1):使用array
而不是tabular
估计的列宽:
\documentclass[12pt, a4paper]{article}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{array} % for wc type column
\begin{document}
\begin{table}[ht!]
\setlength\arraycolsep{4pt}
\renewcommand\arraystretch{1.2}
\centering
\begin{minipage}[t]{0.48\linewidth}
\centering
\[
\begin{array}{|*{5}{wc{2.2em}|}}
\hline
\wedge & \phi & \{a\} & \{b\} & \{a,b\} \\
\hline
\phi & \phi & \phi & \phi & \phi \\
\hline
a &\phi &\{a\} & \phi & \{a\} \\
\hline
b &\phi &\phi & \{b\} & \{b\} \\
\hline
\{a,b\} & \phi &\{a\} & \{b\} & \{a,b\} \\
\hline
\end{array}
\]
\caption{Composition table for meet}
\label{tab:meet}
\end{minipage}%
\hfil%
\begin{minipage}[t]{0.48\linewidth}
\centering
\[
\begin{array}{|*{5}{wc{2.2em}|}}
\hline
\vee & \phi & \{a\} & \{b\} & \{a,b\} \\
\hline
\phi & \phi & \{a\} & \{b\} & \{a,b\} \\
\hline
a & \{a\} & \{a\} & \{a,b\} & \{a,b\} \\
\hline
b & \{b\} & \{a,b\} & \{b\} & \{a,b\} \\
\hline
\{a,b\} & \{a,b\} & \{a,b\} & \{a,b\} & \{a,b\} \\
\hline
\end{array}
\]
\caption{Composition table for join}
\label{tab:join}
\end{minipage}
\end{table}
\end{document}
答案2
这是您的表格的两个版本。在这两个版本中,我都确保两个表格中的所有列都等宽。为此,我将包\widhtof
中的命令calc
与包wc{...}
中的列类型结合使用array
。为了节省$...$
在表格的所有单元格中键入的内容,我还在两个表格的列定义中添加了>{$}
和<{$}
。此外,我略微减小了两个小页面的宽度,以防止标题重叠。我选择了宽度,0.475\textwidth
因为这个宽度允许两个标题仍然适合一行。
应用这些更改后,两个表现在都太宽,无法放入各自的迷你页面中。为了解决这个问题,我将(\tabcolsep
垂直线和单元格实际内容的开始/结束之间的水平空白)的值从默认值减小到。通过此更改,两个表现在都很容易放入其迷你页面中:6pt
4pt
由于水平线非常接近单元格的内容,我使用了包\makegapedcells
中的makecell
方法来对称地增加行高以获得替代输出:
由于两个表格的标题几乎相同,您可能还可以对它们两个使用一个共享的标题:
我还在我的 MWE 中包含了这个第三个版本的代码:
\documentclass[12pt,a4paper]{article} % Replaced unknown option a4size with a4paper
\usepackage{showframe}
\usepackage{array} % Necessary for >{>$} and the wc type column
\usepackage{calc} % necessary for the \widthof command
\usepackage{makecell} % Only needed to symmetrically increase row heights
\setcellgapes{4pt}
\begin{document}
\begin{table}[ht!]
%\makegapedcells % optional. uncomment if you want to get the second output with increased row heights.
\setlength{\tabcolsep}{4pt}
\begin{minipage}[t]{0.475\textwidth}
\centering
\begin{tabular}{|*{5}{>{$}wc{\widthof{\{a,b\}}}<{$}|}}
\hline
\wedge &\phi &\{a\} &\{b\} &\{a,b\}\\
\hline
\phi & \phi &\phi &\phi &\phi\\
\hline
a &\phi &\{a\} &\phi &\{a\}\\
\hline
b &\phi &\phi &\{b\} &\{b\} \\
\hline
\{a,b\} &\phi &\{a\} &\{b\} &\{a,b\} \\
\hline
\end{tabular}
\caption{Composition table for meet}
\end{minipage} \hfill
\begin{minipage}[t]{0.475\textwidth}
\centering
\begin{tabular}{|*{5}{>{$}wc{\widthof{\{a,b\}}}<{$}|}}
\hline
\vee &\phi &\{a\} &\{b\} &\{a,b\}\\
\hline
\phi & \phi &\{a\} &\{b\} &\{a,b\}\\
\hline
a &\{a\} &\{a\} &\{a,b\} &\{a,b\}\\
\hline
b &\{b\} &\{a,b\} &\{b\} &\{a,b\} \\
\hline
\{a,b\} &\{a,b\} &\{a,b\} &\{a,b\} &\{a,b\} \\
\hline
\end{tabular}
\caption{Composition table for join}
\end{minipage}
\end{table}
\begin{table}[ht!]
\makegapedcells % optional. uncomment if you want to get the second output with increased row heights.
\setlength{\tabcolsep}{4pt}
\caption{Composition tables for meet (left) and join (right)}
\begin{tabular}{|*{5}{>{$}wc{\widthof{\{a,b\}}}<{$}|}}
\hline
\wedge &\phi &\{a\} &\{b\} &\{a,b\}\\
\hline
\phi & \phi &\phi &\phi &\phi\\
\hline
a &\phi &\{a\} &\phi &\{a\}\\
\hline
b &\phi &\phi &\{b\} &\{b\} \\
\hline
\{a,b\} &\phi &\{a\} &\{b\} &\{a,b\} \\
\hline
\end{tabular}
\hfill
\begin{tabular}{|*{5}{>{$}wc{\widthof{\{a,b\}}}<{$}|}}
\hline
\vee &\phi &\{a\} &\{b\} &\{a,b\}\\
\hline
\phi & \phi &\{a\} &\{b\} &\{a,b\}\\
\hline
a &\{a\} &\{a\} &\{a,b\} &\{a,b\}\\
\hline
b &\{b\} &\{a,b\} &\{b\} &\{a,b\} \\
\hline
\{a,b\} &\{a,b\} &\{a,b\} &\{a,b\} &\{a,b\} \\
\hline
\end{tabular}
\end{table}
\end{document}