[Tex/LaTex] Adjust column width of a table

tables

I am working on it:

\documentclass{article}
\newcommand\htext[1]{\texttt{0x\MakeLowercase{#1}}}

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\htext{FFFFFFFFFFFFFFFFF} & \htext{FFFFFFFFFFFFFFFFF} & \htext{FFFFFFFFFFFFFFFFF} &  &  &  &  \\
 \hline
\end{tabular}
\end{table}
\end{document}

The empty 4 columns will have something very similar. Now, notice that, an Overfull \hbox error occurs.

How can I adjust width of each column so that each \htext{...} entry is split in to more than one lines (I don't want to reduce font size)? Something like setting p{2in} did not help (as it just created one cell entry overlapping with other).

Best Answer

Here is a solution, adapted from a macro I found on Stack Overflow: I define a \hyphenatestring macro, that takes string, converts it to lower case and makes it ‘hyphenatable anywhere’. This macro can be used inside font-changing commands:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}

\makeatletter
\def\hyphenatestring#1{\xHyphen@te#1$\unskip}
\def\xHyphen@te{\@ifnextchar${\@gobble}{\sw@p{\hskip 0pt plus 1pt\xHyphen@te}}}
\def\sw@p#1#2{\MakeLowercase{{#2}}#1}%\texttt
\makeatother

\newcommand\htexttt[1]{\texttt{\hyphenatestring{0x#1}}}
\newcommand\htextsf[1]{\textsf{\hyphenatestring{0x#1}}}

\begin{document}

\begin{table}[h]
\centering
\begin{tabularx}{\linewidth}{|*{7}{X|}}
\hline
\htexttt{AAAAAAAAAAAAAAAAA}&  & \textbf{\htextsf{CCCCCCCCCCCCCCCCC}} &  & \textit{\htexttt{FFFFFFFFFFFFFFFFF}}{} &  &  \\
 \hline
\end{tabularx}
\end{table}

\end{document} 

enter image description here