0

I have a tabular environment with some columns, but have so far been unable to ensure that long text wraps properly. Instead, the text overflows into the next column. The data being put into the column can sometimes be very long, and may or may not have spaces in it. It often has hyphens, but I do not want these to be seen as places for justification. The behaviour I want is for the text to be put into the column with zero justification - simply render as many characters as possible and then continue on the next line.

An example of what I have at the moment:

\begin{tabular}{c p{4cm} p{7cm} c}
1 & This\_is\_a\_long\_virtual\_machine\_name   &   This\_is\_a\_long\_virtual\_machine\_path & 256\\
\end{tabular}

I need LaTeX to put as much of the long text as possible into the column, and then overflow into the next line. Thanks very much.

3
  • if you use the xurl package you can mark up strings that break on any character Oct 1, 2020 at 15:04
  • Thanks very much, I'll look into that. In the meantime, I have been able to solve this issue by programatically inserting \newline every X characters in the code which generate my .tex file.
    – Sugarat
    Oct 1, 2020 at 15:35
  • sorry about my first deleted comment (which probably shows still in your notifications). It was the right answer to a different question, I mis-read your posting. Oct 1, 2020 at 15:41

3 Answers 3

1

I would use just \- when needed, or in case of many \_ everywhere, as in the MWE, redefine tit to make it breakable:

\let\oldu\_\def\_{\hskip0pt\oldu\hskip0pt}

But you asked what you asked:

It often has hyphens, but I do not want these to be seen as places for justification.

So, it seems that you are looking for `seqsplit, but IMHO is not a nice output:


mwe


\documentclass{article}
\usepackage{seqsplit}
\parskip2em
\begin{document}

With \verb|\seqplit|:

\begin{tabular}{c p{4cm} p{7cm} c} 1 & 
\seqsplit{This\_is\_a\_long\_virtual\_machine\_name}   &   
\seqsplit{This\_is\_a\_long\_virtual\_machine\_path} & 256\\  2 & 
\seqsplit{Supercalifragilisticexpialidocious} & 
\seqsplit{Um-dittle-ittl-um-dittle-I} 
\seqsplit{Um-dittle-ittl-um-dittle-I} 
\seqsplit{Um-dittle-ittl-um-dittle-I} 
\seqsplit{Um-dittle-ittl-um-dittle-I}  & 257
\end{tabular}

Without \verb|\seqplit|:

\begin{tabular}{c p{4cm} p{7cm} c}  1 & 
This\_is\_a\_long\_virtual\_machine\_name  & 
This\_is\_a\_long\_virtual\_machine\_path & 256\\
2 & Supercalifragilisticexpialidocious & 
Um-dittle-ittl-um-dittle-I 
Um-dittle-ittl-um-dittle-I
Um-dittle-ittl-um-dittle-I 
Um-dittle-ittl-um-dittle-I & 257
\end{tabular}

\end{document}
0

A p{} column in a tabular environment provides \newline. This provides a clean line break. I am programatically inserting \newline every X characters in the column, which provides a solution.

0

For hyphenation of long words you can use simbol \- in place where you like to enable hyphenation. Considering this, your table can be rewritten as follows:

\documentclass{article}
\usepackage{tabularx}

\begin{document}

\noindent\begin{tabularx}{\linewidth}{@{} c X X c @{}}
    \hline
1   & This\_is\_a\_long\_virtual\_ma\-chi\-ne\_name   % <---
        &   This\_is\_a\_long\_virtual\_ma\-chi\-ne\_path % <---
            & 256\\
    \hline
\end{tabularx}

\end{document}

enter image description here

(red lines shows text borders)

You must log in to answer this question.

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