1

I'm using a table to show a comparison of two 64-bit blocks/strings — bit for bit.
Like so:


enter image description here


Without the table it of course fits comfortably with room to spare, but when we draw the tables, extra space is added between each value on account of the minimum width of each cell. However, we can override this minimum width by putting \setlength{\tabcolsep}{1.0pt} between \begin{table} & \begin{tabular}. You can go all the way down to 0.0pt (probably even further if you really wanted to), and each cell gets its sides squished in. At 0.5pt, it will fit nicely between my 1.25in margins, but any bigger, it will be flush with the left margin, and overhanging the right.

I'd like to know how to get the table to ignore the margins and become truly centered, relative to the center of the current page. It shouldn't affect anything other than the table (surrounding text for instance). Just a quick temporary override. I thought it was possible with a minipage environment to get a float to.. well float, but I'm not having much luck.

Here's my MWE for the image above:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[a4]{article}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage[margin=1.25in,a4paper,showframe]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\newcommand*{\yncellcolor}{}
\def\yncellcolor\ignorespaces{\@ifnextchar{1}{\cellcolor{green!20}}{\@ifnextchar{0}{\cellcolor{red!20}}{}}}
\newcolumntype{C}{>{\yncellcolor}c}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}\tiny
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}
\centering
\begin{center}
    \setlength{\tabcolsep}{1.0pt}
\begin{tabular}{|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|}

\hline
1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 1 & 1 & 0 & 1 & 0 & 0 & 1 & 1 & 1 \\
\hline
0 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 1 & 1 & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 0 \\
\hline

\end{tabular}
\end{center}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Please, no obvious suggestions about font size, etc. Thanks.

voices
  • 2,039
  • Maybe you can find somethig useful in the answers to this closely related question: How can I center a too wide table? – leandriis Aug 25 '19 at 10:06
  • As a sidenote, you might probably want to replace \begin{tabular}{|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|C|} with \begin{tabular}{*{64}{|C}|} – leandriis Aug 25 '19 at 10:10
  • @leandriis Thanks. I've been scouring the site for related questions. Every time I think I've found a good solution, the output is an empty page. – voices Aug 25 '19 at 10:14
  • Okay, I'll try that. Does it close with \end{tabular} or \end{tabular*}? – voices Aug 25 '19 at 10:17
  • This still closes with \end{tabular}. The * in this case is not the starred version of tabular but a multiplication sign, so |C is repreated 64 times. – leandriis Aug 25 '19 at 10:19
  • \begin{table} \makebox[\textwidth][c]{ \setlength{\tabcolsep}{1.0pt} \begin{tabular}{*{64}{|C}|} \hline ... \hline 0 & 1 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 1 & 1 & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 & 1 & 0 & 0 & 0 \\ \hline \end{tabular}} \end{table} works fine for me and centers the table relative to the textblock spilling equally into the left and right margin. – leandriis Aug 25 '19 at 10:20
  • I see, so instead of wrapping the tabular environment with a minipage environment (or whatever), you've wrapped it with \makebox[\textwidth][c]{ }, right? It seems to work, if you would like to put it in a formal answer, I can award you credit. – voices Aug 25 '19 at 10:29
  • That's right. Even better than the \makebox solution is most likely using begin{adjustbox}{center} around the tabular (or instead of) but inside of table as explained by Martin Scharrer in his anwer – leandriis Aug 25 '19 at 10:53
  • Instead of adding an answer, I'd usggest closing your question as a duplicate of How can I center a too wide table?. Would you agree? – leandriis Aug 25 '19 at 10:54
  • Another unrelated suggestion, but you might want to replace \usepackage{colortbl} \usepackage{xcolor} by \usepackage[table]{xcolor}. – leandriis Aug 25 '19 at 10:55
  • @leandriis I would if the questions were the same, but they are at most related. Besides, I often lack the skill to answer other questions, so I generally try to include something of value in my own. I would keep it if only for the comp-sci neophytes seeking ways to present a bitwise visual comparison of booleans/bytes/blocks/etc. Feel free to add as many solutions and their pros/cons as you like though. – voices Aug 25 '19 at 11:19
  • I guess you weren't actually interested in my opinion then. – voices Aug 25 '19 at 11:21
  • 1
    I'm sorry, by my close vote I did not mean to insult you. Nevertheless, I still think "[...] get the table to ignore the margins and become truly centered, relative to the center of the current page [...]" and "[...] instead of growing to the right side only, I would like to have it centered on the page [...]" is basically the same question regardless of the actual contents of the table (that seem to be irrelevant for the alignment issue). If there is something else that I still overlook in your well written question, please let me know. – leandriis Aug 25 '19 at 16:11

0 Answers0