Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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 Aug 10 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. –  pushpen.paul Aug 10 at 21:13
    
You probably want to use a variation on tabular{|p{40cm}|... or tabularx{|X|...} with the tabularx package. –  Andrew Aug 10 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 Aug 10 at 21:26
1  
Splitting a 22 character string into two will not work, because seven columns would still be too wide. –  egreg Aug 10 at 21:57

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
Overfull \hbox still remains. Anyway, I appreciate your attempt. –  pushpen.paul Aug 10 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 Aug 10 at 23:06
2  
Why \-? You can add \hspace{0pt} and no hyphen will show. –  egreg Aug 10 at 23:07
    
@egreg Perfect. I didn't know that –  Zé Loff Aug 10 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. –  pushpen.paul Aug 11 at 4:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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