1

I have a longtable that technically consists of three columns. However, the third column is just a mark (like a *) to the corresponding row (see picture for clarification).
I want LaTeX to center my table horizontally, but I want it to ignore the third column while doing so. In other words: if my table had two rows, it should be regularly centered. If I then add the third row, the table should not shift horizontally.

Is this doable?

Picture of the table I described above.

MWE:

\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}
2

One (rude) solution is add empty column on the table left side with width of last column:

enter image description here enter image description here

Slightly simplified code is:

\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}

As alternative is table without vertical rules and with horizontal rules from package booktabs. Last part of such designed table is:

enter image description here

and 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}

I would rather check if this this long table split into two half and positioned in parallel can fit on one page:

enter image description here

\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}
  • Two questions arise: 1) Where does \hphantom come from? array, longtable or standard LaTeX? 2) How does booktabs center the table? I.e. how do I control its centering behaviour? – gebruiker Jul 17 '17 at 11:11
  • (i) hphantom{...} is defined in LaTeX kernel , (ii) booktabs doesn't center anything. for last example should be present \centering, which is (I see now, corrected) accidentally erased. – Zarko Jul 17 '17 at 11:20
0

Here I introduce \fauxcol that one actually uses at the end of the column 2 data. It assumes certain things:

  1. \tabcolsep column separation is in force,

  2. all table data has the vertical footprint of a \strut.

The MWE:

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.