2

I want to display some hexcode aligned in a table. This is what I got:

messed up table

\begin{table}[h]
\caption{Dirty table}
\centering
\begin{tabular}{p{6cm}|p{6cm}}
\textcolor{red}{0000 0000 0001 0000 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000} 0014 0000 0000 0000 0000 usw.
&
\textcolor{red}{0000 0000 0001 0000 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000} 001a 0000 0000 0000 0000 usw.
 \end{tabular}
\label{tab:BitcoinCoreMobileSignatur}
\end{table}

How to align this hex blocks correctly? I tried siuntix Package with

\begin{tabular}{S[table-column-width=6cm]|S[table-column-width=6cm]}

with some more variations found here. You have some ideas?

Thanks

  • welcome to tex.sx. the problem is that the widths of the letters aren't uniform. for that, you'd ideally use a monospace font, but you most likely don't want the usual "typewriter" font. perhaps someone knows of a more appropriate one. – barbara beeton Mar 5 '16 at 17:16
  • you didn't get that image from that input I assume, the code for the image would have been a better test the posted code exactly aligns already as all the digits, and a have the same width in computer modern. – David Carlisle Mar 5 '16 at 17:40
  • @ david I exaclty get this image from this code. but anyways, thank you and with egreg answer now its fine – mho Mar 5 '16 at 20:11
1

You should use a monospaced font. Here it is with Inconsolata:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{inconsolata}
\usepackage{xcolor,array}

\newlength{\hexcodewidth}

\begin{document}

\begin{table}[htp]
\centering

\caption{Dirty table}\label{tab:BitcoinCoreMobileSignatur}

\medskip

\ttfamily
\settowidth{\hexcodewidth}{0}% width of a character
\setlength{\hexcodewidth}{\dimexpr24\hexcodewidth+1em}% 24 characters per line
\setlength{\spaceskip}{\dimexpr1em/5}% five spaces

\begin{tabular}{p{\hexcodewidth}|p{\hexcodewidth}}
\textcolor{red}{%
  0000  0000  0001 0000  0000  0000
  3162  0005  0009 0000  1000  0000
  0900  0000  0000 0000} 0014  0000
  0000  0000  0000 usw.
&
\textcolor{red}{%
  0000  0000  0001  0000  0000  0000
  3162  0005  0009  0000  1000  0000
  0900  0000  0000  0000} 001a  0000
  0000 0000 0000 usw.
\end{tabular}

\end{table}

\end{document}

enter image description here

1

You could use a monospace font, or use a normal font but set each hex digit in a fixed width box.

enter image description here

\documentclass{article}
\usepackage{color,array}
\settowidth{\dimen0}{1}
\def\z#1{\zz#1 !!!!}
\def\zz#1#2#3#4{%
\ifx!#1\unskip\else
\makebox[\dimen0]{#1}%
\makebox[\dimen0]{#2}%
\makebox[\dimen0]{#3}%
\makebox[\dimen0]{#4}%
\space
\expandafter\zz
\fi}
\newcolumntype{P}{>{\raggedright\arraybackslash}p}

\addtolength\textwidth{40pt}
\begin{document}


\begin{tabular}{P{6cm}|P{6cm}}
\textcolor{red}{0000 00ag 0001 0eef 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000} 0014 0000 0000 0000 0000 usw.
&
\textcolor{red}{ccf0  fff1 0000 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000} 001a 0000 0000 0000 0000 usw.
 \end{tabular}

\bigskip

{\ttfamily
\begin{tabular}{P{6cm}|P{6cm}}
\textcolor{red}{0000 00ag 0001 0eef 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000} 0014 0000 0000 0000 0000 usw.
&
\textcolor{red}{ccf0  fff1 0000 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000} 001a 0000 0000 0000 0000 usw.
 \end{tabular}}


\bigskip


\begin{tabular}{P{6cm}|P{6cm}}
\textcolor{red}{\z{0000 00ag 0001 0eef 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000}}
\z{0014 0000 0000 0000 0000 usw.}
&
\textcolor{red}{\z{ccf0  fff1 0000 0000 0000 3162 0005 0009 0000 1000 0000 0900 0000 0000 0000}}
\z{001a 0000 0000 0000 0000 usw.}
 \end{tabular}




\end{document}

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.