2

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).

8
  • 2
    Do you any suggestions or requirements for how the string FFFFFFFFFFFFFFFFF might be split across two lines? Maybe unsurprisingly, TeX does not appear to have a hyphenation rule for this string, so you need to provide such information explicitly. Separately, are you really looking to typeset tables containing strings of FFFFFFFFFFFFFFFFF (or ffffffffffffff? Must make for really fascinating reading... :-)
    – Mico
    Commented Aug 10, 2014 at 21:08
  • @Mico Just splitting across two lines is sufficient - no hyphenation needed. For your 2nd query, I need to write hex strings of 17 to 20 characters (not all are equal to FFFFFFFFFFFFFFFFF, of course). I have used FFFFFFFFFFFFFFFFF just to illustrate the scenario.
    – hola
    Commented Aug 10, 2014 at 21:13
  • You probably want to use a variation on tabular{|p{40cm}|... or tabularx{|X|...} with the tabularx package.
    – user30471
    Commented Aug 10, 2014 at 21:15
  • 1
    @Andrew - What the OP is encountering is that TeX does not "know" how and where to split up these rather long hex strings.
    – Mico
    Commented Aug 10, 2014 at 21:26
  • 1
    Splitting a 22 character string into two will not work, because seven columns would still be too wide.
    – egreg
    Commented Aug 10, 2014 at 21:57

2 Answers 2

4

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

3

Borrowing from the answer to this, you can define a command to insert a hyphenation break after each character.

\usepackage{xparse}

\NewDocumentCommand{\splitlist}{>{\SplitList{}}m}
 {\ProcessList{#1}{\addabreak}\unskip}
\newcommand{\addabreak}[1]{#1\-}

After that, you can redefine your command to make use of this:

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

And then play with the column widths until it fits your needs:

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\splitlist}{>{\SplitList{}}m}
 {\ProcessList{#1}{\addabreak}\unskip}
\newcommand{\addabreak}[1]{#1\-}

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

\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|p{0.11\textwidth}|p{0.11\textwidth}|p{0.11\textwidth}|%
p{0.11\textwidth}|p{0.11\textwidth}|p{0.11\textwidth}|p{0.11\textwidth}|}
\hline
\htext{FFFFFFFFFFFFFFFFF} & \htext{FFFFFFFFFFFFFFFFF} &
\htext{FFFFFFFFFFFFFFFFF} & \htext{FFFFFFFFFFFFFFFFF} &
\htext{FFFFFFFFFFFFFFFFF} & \htext{FFFFFFFFFFFFFFFFF} &
\htext{FFFFFFFFFFFFFFFFF} \\
 \hline
\end{tabular}
\end{table}
\end{document}

Result:

MWE

5
  • Overfull \hbox still remains. Anyway, I appreciate your attempt.
    – hola
    Commented Aug 10, 2014 at 23:01
  • Are you sure it was overfull? I got underfull on this example (probably because of that last 'f'), but like I said, you can fiddle with the column widths. I didn't test it until the error was gone because it will depend on your paper size, font size, etc, so there is no one-size-fits-all solution, I think.
    – Zé Loff
    Commented Aug 10, 2014 at 23:06
  • 2
    Why \-? You can add \hspace{0pt} and no hyphen will show.
    – egreg
    Commented Aug 10, 2014 at 23:07
  • @egreg Perfect. I didn't know that
    – Zé Loff
    Commented Aug 10, 2014 at 23:09
  • @ZéLoff Here goes the error: line 13: Overfull \hbox (4.65147pt too wide) in paragraph. Before that, there are 14 Underfull \hboxes also.
    – hola
    Commented Aug 11, 2014 at 4:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .