我有一个长表,严格来说它由三列组成。但是,第三列只是对应行的一个标记(类似 *)(请参见图片以了解详情)。
我希望 LaTeX 将我的表格水平居中,但我希望它在这样做时忽略第三列。换句话说:如果我的表格有两行,它应该规则地居中。如果我添加第三行,表格不应该水平移动。
这可行吗?
梅威瑟:
\documentclass[a4paper]{article}
\usepackage{longtable}
\begin{document}
\vspace*{3cm}
\begin{longtable}{|c|c|c}
\caption{Caption1}\\
\cline{1-2}
$\mathbf{\{p,q\}}$&$\mathbf{(V,E,F)}$&~\endfirsthead
\caption{caption2}\\
\cline{1-2}
$\mathbf{\{p,q\}}$&$\mathbf{(V,E,F)}$&~\\\cline{1-2}\endhead
\cline{1-2}
$\{3,7\}$&$(36,126,84)$&\\
\cline{1-2}
$\{3,8\}$&$(18,72,48)$&\\
\cline{1-2}
$\{3,9\}$&$(12,54,36)$&\\
\cline{1-2}
$\{3,10\}$&$(9,45,30)$&\\
\cline{1-2}
$\{3,12\}$&$(6,36,24)$&\\
\cline{1-2}
$\{3,15\}$&$(4,30,20)$&\\
\cline{1-2}
$\{3,18\}$&$(3,27,18)$&\\
\cline{1-2}
$\{3,24\}$&$(2,24,16)$&\\
\cline{1-2}
$\{3,42\}$&$(1,21,14)$&\\
\cline{1-2}
$\{4,5\}$&$(24,60,30)$&\\
\cline{1-2}
$\{4,6\}$&$(12,36,18)$&\\
\cline{1-2}
$\{4,7\}$&$(8,28,14)$&\\
\cline{1-2}
$\{4,8\}$&$(6,24,12)$&\\
\cline{1-2}
$\{4,10\}$&$(4,20,10)$&\\
\cline{1-2}
$\{4,12\}$&$(3,18,9)$&\\
\cline{1-2}
$\{4,16\}$&$(2,16,8)$&\\
\cline{1-2}
$\{4,28\}$&$(1,14,7)$&\\
\cline{1-2}
$\{5,4\}$&$(30,60,24)$&\\
\cline{1-2}
$\{5,5\}$&$(12,30,12)$&\\
\cline{1-2}
$\{5,10\}$&$(3,15,6)$&\\
\cline{1-2}
$\{6,4\}$&$(18,36,12)$&\\
\cline{1-2}
$\{6,6\}$&$(6,18,6)$&\\
\cline{1-2}
$\{6,12\}$&$(2,12,4)$&\\
\cline{1-2}
$\{7,3\}$&$(84,126,36)$&\\
\cline{1-2}
$\{7,4\}$&$(14,28,8)$&\\
\cline{1-2}
$\{7,7\}$&$(4,14,4)$&\\
\cline{1-2}
$\{8,3\}$&$(48,72,18)$&\\
\cline{1-2}
$\{8,4\}$&$(12,24,6)$&\\
\cline{1-2}
$\{8,8\}$&$(3,12,3)$&\\
\cline{1-2}
$\{9,3\}$&$(36,54,12)$&\\
\cline{1-2}
$\{9,18\}$&$(1,9,2)$&\\
\cline{1-2}
$\{10,3\}$&$(30,45,9)$&\\
\cline{1-2}
$\{10,4\}$&$(10,20,4)$&\\
\cline{1-2}
$\{10,5\}$&$(6,15,3)$&\\
\cline{1-2}
$\{10,10\}$&$(2,10,2)$&\\
\cline{1-2}
$\{12,3\}$&$(24,36,6)$&\\
\cline{1-2}
$\{12,4\}$&$(9,18,3)$&\\
\cline{1-2}
$\{12,6\}$&$(4,12,2)$&\\
\cline{1-2}
$\{15,3\}$&$(20,30,4)$&\\
\cline{1-2}
$\{16,4\}$&$(8,16,2)$&\\
\hline
$\{16,16\}$&$(1,8,1)$&\multicolumn{1}{c|}{FP}\\
\cline{1-3}
$\{18,3\}$&$(18,27,3)$&\\
\hline
$\{18,9\}$&$(2,9,1)$&\multicolumn{1}{c|}{FP}\\
\cline{1-3}
$\{24,3\}$&$(16,24,2)$&\\
\hline
$\{28,4\}$&$(7,14,1)$&\multicolumn{1}{c|}{FP}\\
\hline
$\{42,3\}$&$(14,21,1)$&\multicolumn{1}{c|}{FP}\\
\hline
\end{longtable}
\end{document}
答案1
一个(粗鲁的)解决方案是在表格左侧添加一个空列,其宽度与最后一列相同:
稍微简化的代码是:
\documentclass[a4paper]{article}
\usepackage{array, longtable}
%-------------------------------------- only for show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.25pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\vspace*{3cm}
\begin{longtable}{>{\hphantom{FP}}c|>{$}c<{$}|>{$}c<{$}|c}
\caption{Caption1}\\
\cline{2-3}
& \mathbf{\{p,q\}}&\mathbf{(V,E,F)}&~\endfirsthead
\caption{caption2}\\
\cline{2-3}
& \mathbf{\{p,q\}}&\mathbf{(V,E,F)}&~\\\cline{2-3}\endhead
\cline{2-3}
& \{3,7\}&(36,126,84)&\\
\cline{2-3}
& \{3,8\}&(18,72,48)&\\
\cline{2-3}
& \{3,9\}&(12,54,36)&\\
\cline{2-3}
& \{3,10\}&(9,45,30)&\\
\cline{2-3}
& \{3,12\}&(6,36,24)&\\
\cline{2-3}
& \{3,15\}&(4,30,20)&\\
\cline{2-3}
& \{3,18\}&(3,27,18)&\\
\cline{2-3}
& \{3,24\}&(2,24,16)&\\
\cline{2-3}
& \{3,42\}&(1,21,14)&\\
\cline{2-3}
& \{4,5\}&(24,60,30)&\\
\cline{2-3}
& \{4,6\}&(12,36,18)&\\
\cline{2-3}
& \{4,7\}&(8,28,14)&\\
\cline{2-3}
& \{4,8\}&(6,24,12)&\\
\cline{2-3}
& \{4,10\}&(4,20,10)&\\
\cline{2-3}
& \{4,12\}&(3,18,9)&\\
\cline{2-3}
& \{4,16\}&(2,16,8)&\\
\cline{2-3}
& \{4,28\}&(1,14,7)&\\
\cline{2-3}
& \{5,4\}&(30,60,24)&\\
\cline{2-3}
& \{5,5\}&(12,30,12)&\\
\cline{2-3}
& \{5,10\}&(3,15,6)&\\
\cline{2-3}
& \{6,4\}&(18,36,12)&\\
\cline{2-3}
& \{6,6\}&(6,18,6)&\\
\cline{2-3}
& \{6,12\}&(2,12,4)&\\
\cline{2-3}
& \{7,3\}&(84,126,36)&\\
\cline{2-3}
& \{7,4\}&(14,28,8)&\\
\cline{2-3}
& \{7,7\}&(4,14,4)&\\
\cline{2-3}
& \{8,3\}&(48,72,18)&\\
\cline{2-3}
& \{8,4\}&(12,24,6)&\\
\cline{2-3}
& \{8,8\}&(3,12,3)&\\
\cline{2-3}
& \{9,3\}&(36,54,12)&\\
\cline{2-3}
& \{9,18\}&(1,9,2)&\\
\cline{2-3}
& \{10,3\}&(30,45,9)&\\
\cline{2-3}
& \{10,4\}&(10,20,4)&\\
\cline{2-3}
& \{10,5\}&(6,15,3)&\\
\cline{2-3}
& \{10,10\}&(2,10,2)&\\
\cline{2-3}
& \{12,3\}&(24,36,6)&\\
\cline{2-3}
& \{12,4\}&(9,18,3)&\\
\cline{2-3}
& \{12,6\}&(4,12,2)&\\
\cline{2-3}
& \{15,3\}&(20,30,4)&\\
\cline{2-3}
& \{16,4\}&(8,16,2)&\\
\cline{2-4}
& \{16,16\}&(1,8,1)&\multicolumn{1}{c|}{FP}\\
\cline{2-4}
& \{18,3\}&(18,27,3)&\\
\cline{2-4}
& \{18,9\}&(2,9,1)&\multicolumn{1}{c|}{FP}\\
\cline{2-4}
& \{24,3\}&(16,24,2)&\\
\cline{2-4}
& \{28,4\}&(7,14,1)&\multicolumn{1}{c|}{FP}\\
\cline{2-4}
& \{42,3\}&(14,21,1)&\multicolumn{1}{c|}{FP}\\
\cline{2-4}
\end{longtable}
\end{document}
另一种方法是使用没有垂直线和带有水平线的表格booktabs
。这种设计的表格的最后部分是:
和 MWE:
\documentclass[a4paper]{article}
\usepackage{array, booktabs, longtable}
%-------------------------------------- only for show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.25pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\vspace*{3cm}
\begin{longtable}{>{\hphantom{FP}}c>{$}c<{$}>{$}c<{$}c}
\caption{Caption1}\\
\cmidrule[0.8pt]{2-3}
& \mathbf{\{p,q\}}&\mathbf{(V,E,F)}& \\
\cmidrule[0.4pt]{2-3}
\endfirsthead
\caption{caption2}\\
\cmidrule[0.8pt]{2-3}
& \mathbf{\{p,q\}}&\mathbf{(V,E,F)}&~\\
\cmidrule[0.4pt]{2-3}
\endhead
& \{3,7\}&(36,126,84)&\\
& \{3,8\}&(18,72,48)&\\
& \{3,9\}&(12,54,36)&\\
& \{3,10\}&(9,45,30)&\\
\addlinespace
& \{3,12\}&(6,36,24)&\\
& \{3,15\}&(4,30,20)&\\
& \{3,18\}&(3,27,18)&\\
& \{3,24\}&(2,24,16)&\\
\addlinespace
& \{3,42\}&(1,21,14)&\\
& \{4,5\}&(24,60,30)&\\
& \{4,6\}&(12,36,18)&\\
& \{4,7\}&(8,28,14)&\\
\addlinespace
& \{4,8\}&(6,24,12)&\\
& \{4,10\}&(4,20,10)&\\
& \{4,12\}&(3,18,9)&\\
& \{4,16\}&(2,16,8)&\\
\addlinespace
& \{4,28\}&(1,14,7)&\\
& \{5,4\}&(30,60,24)&\\
& \{5,5\}&(12,30,12)&\\
& \{5,10\}&(3,15,6)&\\
\addlinespace
& \{6,4\}&(18,36,12)&\\
& \{6,6\}&(6,18,6)&\\
& \{6,12\}&(2,12,4)&\\
& \{7,3\}&(84,126,36)&\\
\addlinespace
& \{7,4\}&(14,28,8)&\\
& \{7,7\}&(4,14,4)&\\
& \{8,3\}&(48,72,18)&\\
& \{8,4\}&(12,24,6)&\\
\addlinespace
& \{8,8\}&(3,12,3)&\\
& \{9,3\}&(36,54,12)&\\
& \{9,18\}&(1,9,2)&\\
& \{10,3\}&(30,45,9)&\\
\addlinespace
& \{10,4\}&(10,20,4)&\\
& \{10,5\}&(6,15,3)&\\
& \{10,10\}&(2,10,2)&\\
& \{12,3\}&(24,36,6)&\\
\addlinespace
& \{12,4\}&(9,18,3)&\\
& \{12,6\}&(4,12,2)&\\
& \{15,3\}&(20,30,4)&\\
& \{16,4\}&(8,16,2)&\\
\addlinespace
& \{16,16\}&(1,8,1)& {FP}\\
& \{18,3\}&(18,27,3)&\\
& \{18,9\}&(2,9,1) & {FP}\\
& \{24,3\}&(16,24,2)&\\
\addlinespace
& \{28,4\}&(7,14,1)& {FP}\\
& \{42,3\}&(14,21,1)& {FP}\\
\cmidrule[0.8pt]{2-3}
\end{longtable}
\end{document}
我宁愿检查这张分成两半并平行放置的长表是否可以放在一页上:
\documentclass[a4paper]{article}
\usepackage{array, booktabs, longtable}
%-------------------------------------- only for show page layout
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.25pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[htb]
\centering
\caption{Caption1}
\begin{tabular}[t]{>{\hphantom{FP}}c>{$}c<{$}>{$}c<{$}c}
\cmidrule[0.8pt]{2-3}
& \mathbf{\{p,q\}}&\mathbf{(V,E,F)}& \\
\cmidrule[0.4pt]{2-3}
& \{3,7\}&(36,126,84)&\\
& \{3,8\}&(18,72,48)&\\
& \{3,9\}&(12,54,36)&\\
& \{3,10\}&(9,45,30)&\\
\addlinespace
& \{3,12\}&(6,36,24)&\\
& \{3,15\}&(4,30,20)&\\
& \{3,18\}&(3,27,18)&\\
& \{3,24\}&(2,24,16)&\\
\addlinespace
& \{3,42\}&(1,21,14)&\\
& \{4,5\}&(24,60,30)&\\
& \{4,6\}&(12,36,18)&\\
& \{4,7\}&(8,28,14)&\\
\addlinespace
& \{4,8\}&(6,24,12)&\\
& \{4,10\}&(4,20,10)&\\
& \{4,12\}&(3,18,9)&\\
& \{4,16\}&(2,16,8)&\\
\addlinespace
& \{4,28\}&(1,14,7)&\\
& \{5,4\}&(30,60,24)&\\
& \{5,5\}&(12,30,12)&\\
& \{5,10\}&(3,15,6)&\\
\addlinespace
& \{6,4\}&(18,36,12)&\\
& \{6,6\}&(6,18,6)&\\
& \{6,12\}&(2,12,4)&\\
& \{7,3\}&(84,126,36)&\\
\cmidrule[0.8pt]{2-3}
\end{tabular}%
\quad% space between tables
\begin{tabular}[t]{>{\hphantom{FP}}c>{$}c<{$}>{$}c<{$}c}
\cmidrule[0.8pt]{2-3}
& \mathbf{\{p,q\}}&\mathbf{(V,E,F)}& \\
\cmidrule[0.4pt]{2-3}
& \{7,4\}&(14,28,8)&\\
& \{7,7\}&(4,14,4)&\\
& \{8,3\}&(48,72,18)&\\
& \{8,4\}&(12,24,6)&\\
\addlinespace
& \{8,8\}&(3,12,3)&\\
& \{9,3\}&(36,54,12)&\\
& \{9,18\}&(1,9,2)&\\
& \{10,3\}&(30,45,9)&\\
\addlinespace
& \{10,4\}&(10,20,4)&\\
& \{10,5\}&(6,15,3)&\\
& \{10,10\}&(2,10,2)&\\
& \{12,3\}&(24,36,6)&\\
\addlinespace
& \{12,4\}&(9,18,3)&\\
& \{12,6\}&(4,12,2)&\\
& \{15,3\}&(20,30,4)&\\
& \{16,4\}&(8,16,2)&\\
\addlinespace
& \{16,16\}&(1,8,1)& {FP}\\
& \{18,3\}&(18,27,3)&\\
& \{18,9\}&(2,9,1) & {FP}\\
& \{24,3\}&(16,24,2)&\\
\addlinespace
& \{28,4\}&(7,14,1)& {FP}\\
& \{42,3\}&(14,21,1)& {FP}\\
%& & & \\
%& & & \\
\cmidrule[0.8pt]{2-3}
\end{tabular}
\end{table}
\end{document}
答案2
这里我介绍一下\fauxcol
人们实际使用的第 2 列末尾的数据。它假设了某些事情:
\tabcolsep
柱分离有效,所有表格数据都有 的垂直足迹
\strut
。
妇女权利委员会:
\documentclass{article}
\usepackage{tabularx}
\def\fauxcol#1{\unskip\smash{\rlap{\fboxsep=0pt\relax\hspace{\tabcolsep}\fbox{%
\hspace{\tabcolsep}#1\strut\hspace{\tabcolsep}}}}}
\begin{document}
\begin{table}[ht]
\centering
\caption{Two-column table}
\begin{tabular}{|c|c|}
\hline
the & end\\
\hline
x & y\\
\hline
\end{tabular}
\end{table}
\begin{table}[ht]
\centering
\caption{Extra faux column}
\begin{tabular}{|c|c|}
\hline
the & end\fauxcol{FP}\\
\hline
x & y\\
\hline
\end{tabular}
\end{table}
\end{document}