0

I have a table in tabularx, and I need to put an url into one of the columns. The best and probably easiest solution for me would be to use:

\truncate{200pt}{url}

from the truncate package, which will make sure the url is not too long, in combination with

\seqsplit{url}

from the seqsplit package, to allow the url to span over multiple rows. Both of these work correctly when used alone.

I figured, I could just combine both of these commands, to achieve my goal, but when combined as such:

\seqsplit{\truncate{200pt}{https://www.google.com/maps/place/somereallycoolplaceineedtoputherethatisalsoverylongwithitsurlandsimplywontfitintothetable}}

Neither works and I just get errors, after a little bit of googling I learned, that this is because \seqsplit{} doesn't like to play with macros.

Later on I've also learned about the

\expandafter

macro. Which sounds fairly simple to use in the wiki, but when put to real use it's even more confusing, nevertheless, I've tried and came up with:

\expandafter\seqsplit\expandafter{{\truncate{100pt}{https://www.google.com/maps/place/somereallycoolplaceineedtoputherethatisalsoverylongwithitsurlandsimplywontfitintothetable}}}

which only allows the url to be truncated, but somehow ignores the seqsplit command?

My question is, how can I achieve truncating the url, but also allowing it to span over multiple rows. It doesn't have to be done with the \truncate and \seqsplit commands, it's just what I came across, also I would prefer a solution that won't force me to redo the whole table.

The reason why I'm not including the code of the table is, because this issue is prevalent in the plain text as well, not just in the table, I believe the table has nothing to do with it, although feel free to ask me to provide it if necessary!

Also I'm pretty sure there's tons of similar questions, but I'm just unable to figure this one out, so sorry for that!

EDIT: After further investigation, this issue exists only within the tables, so I'm including the code for the table as well, that should explain the issue well enough.

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{seqsplit}
\usepackage[breakall]{truncate}

\begin{document}

\begin{table}
    \begin{tabularx}{\textwidth}{|X|X|}
        \toprule
Test1 &
Test2 \\
        \midrule
lenghty &
xxx \\
\hline
This is wrong, because it is not truncated: &
\seqsplit{https://www.google.com/maps/place/Place+I+Think+Is+Cool/@22.2256554,21.6147546,15z/data=!4m13!1m6!3m5!1s0x474294571e2a0dbd:0x627721723bd8ab4d!2zVSBEx5alla3sSbbsOpaG8gT3JsYQ!8m2!3d49.193308342342kkfai!3m6!1s0x471293c2e9b76cf1:0x534b6a5fd7225cbc!8m2!3d49.2545445!4d16.6228957!9m1!1b1} \\

\hline
This is wrong, because it is not split: &
\truncate{250pt}{https://www.google.com/maps/place/Place+I+Think+Is+Cool/@22.2256554,21.6147546,15z/data=!4m13!1m6!3m5!1s0x474294571e2a0dbd:0x627721723bd8ab4d!2zVSBEx5alla3sSbbsOpaG8gT3JsYQ!8m2!3d49.193308342342kkfai!3m6!1s0x471293c2e9b76cf1:0x534b6a5fd7225cbc!8m2!3d49.2545445!4d16.6228957!9m1!1b1} \\
\hline
This is also wrong, because it is not split, although it should be: &
\expandafter\seqsplit\expandafter{{\truncate{250pt}{https://www.google.com/maps/place/Place+I+Think+Is+Cool/@22.2256554,21.6147546,15z/data=!4m13!1m6!3m5!1s0x474294571e2a0dbd:0x627721723bd8ab4d!2zVSBEx5alla3sSbbsOpaG8gT3JsYQ!8m2!3d49.193308342342kkfai!3m6!1s0x471293c2e9b76cf1:0x534b6a5fd7225cbc!8m2!3d49.2545445!4d16.6228957!9m1!1b1}}} \\
        \bottomrule
    \end{tabularx}
    \vskip\abovecaptionskip\emph{From Test}
    \caption{Test}
    \label{tab:test}
\end{table}

\end{document}

This is the preview

From the image the problem should be obvious, I want the text truncated as well as split.

6
  • Welcome to TeX.SE :) // Please complete your code via the Edit button, so we can copy and run it. Thanks
    – MS-SPO
    Apr 27, 2022 at 15:13
  • 1
    What's the point of including the url but truncating it? If I'm not mistaken, the reader won't be able to follow the url, so you don't really provide any useful information by including a url that is simply cut off after a certain amount of characters. For a shorter entry in the table in combination with still retaining the entire url, you could use \href{url}{link text} (needs the hyperref package).
    – leandriis
    Apr 27, 2022 at 15:59
  • @MS-SPO Thanks, included a runnable code! :)
    – duzda
    Apr 27, 2022 at 22:07
  • @leandriis Yes you're correct, the reader won't be able to follow the url, but this is not a problem, as the table is more of a just showcase than anything else. Think of it as any other text without spaces. Thanks for mentioning \href, but this is not something that fits my needs.
    – duzda
    Apr 27, 2022 at 22:10
  • why than yo not manually cut to the desired lenght (by using ˙href) as suggested @leandriis?
    – Zarko
    Sep 25, 2022 at 6:09

1 Answer 1

0

The common way to do it is using package hyperref, where you replace your commands simply by \url{someURL}.

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx}
  %\usepackage{seqsplit}
  %\usepackage[breakall]{truncate}

\usepackage{hyperref}% <<<---

\begin{document}

\begin{table}
    \begin{tabularx}{\textwidth}{|X|X|}
        \toprule
Test1 &
Test2 \\
        \midrule
lenghty &
xxx \\
\hline
changed +++ This is wrong, because it is not truncated: &
\url{https://www.google.com/maps/place/Place+I+Think+Is+Cool/@22.2256554,21.6147546,15z/data=!4m13!1m6!3m5!1s0x474294571e2a0dbd:0x627721723bd8ab4d!2zVSBEx5alla3sSbbsOpaG8gT3JsYQ!8m2!3d49.193308342342kkfai!3m6!1s0x471293c2e9b76cf1:0x534b6a5fd7225cbc!8m2!3d49.2545445!4d16.6228957!9m1!1b1} \\

\hline
changed +++ This is wrong, because it is not split: &
\url{https://www.google.com/maps/place/Place+I+Think+Is+Cool/@22.2256554,21.6147546,15z/data=!4m13!1m6!3m5!1s0x474294571e2a0dbd:0x627721723bd8ab4d!2zVSBEx5alla3sSbbsOpaG8gT3JsYQ!8m2!3d49.193308342342kkfai!3m6!1s0x471293c2e9b76cf1:0x534b6a5fd7225cbc!8m2!3d49.2545445!4d16.6228957!9m1!1b1} \\
\hline
changed +++ This is also wrong, because it is not split, although it should be: &
\url{https://www.google.com/maps/place/Place+I+Think+Is+Cool/@22.2256554,21.6147546,15z/data=!4m13!1m6!3m5!1s0x474294571e2a0dbd:0x627721723bd8ab4d!2zVSBEx5alla3sSbbsOpaG8gT3JsYQ!8m2!3d49.193308342342kkfai!3m6!1s0x471293c2e9b76cf1:0x534b6a5fd7225cbc!8m2!3d49.2545445!4d16.6228957!9m1!1b1} \\
        \bottomrule
    \end{tabularx}
    \vskip\abovecaptionskip\emph{From Test}
    \caption{Test}
    \label{tab:test}
\end{table}

\end{document}

Result:

enter image description here

1
  • Thank you for showing a slightly different approach, this however also doesn't truncate the url? The url doesn't have to followable nor clickable, just truncated to for example 3 rows. As you can see in my example the truncated url ends with "Thin...", which is the behavior I'm trying to achieve.
    – duzda
    Apr 29, 2022 at 6:44

You must log in to answer this question.

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