同时使用 seqsplit 和 truncate

同时使用 seqsplit 和 truncate

我在 tabularx 中有一个表格,我需要在其中一列中放入一个 url。对我来说,最好且可能最简单的解决方案是使用:

\truncate{200pt}{url}

来自 truncate 包,它将确保 URL 不会太长,结合

\seqsplit{url}

来自 seqsplit 包,允许 url 跨越多行。单独使用时,这两个都可以正常工作。

我认为,我可以将这两个命令结合起来,以实现我的目标,但是当这样组合时:

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

两者都不起作用,我只是收到错误,经过一点谷歌搜索后我了解到,这是因为 \seqsplit{} 不喜欢使用宏。

后来我还了解到

\expandafter

宏。在 wiki 上听起来相当简单,但实际使用时就更加令人困惑了,不过,我尝试了一下,并得出了以下结论:

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

它只允许截断 url,但以某种方式忽略了 seqsplit 命令?

我的问题是,如何才能实现截断 URL,同时又允许它跨越多行。这不一定非要使用 \truncate 和 \seqsplit 命令,这只是我遇到的情况,而且我更喜欢一种不会强迫我重做整个表格的解决方案。

我之所以没有包含表格代码,是因为这个问题在纯文本中也很普遍,而不仅仅是在表格中,我相信表格与此无关,但如果有必要,请随时让我提供它!

另外,我很确定还有很多类似的问题,但我就是无法解决这个问题,所以很抱歉!

编辑:经过进一步调查,该问题仅存在于表格中,因此我还包括了表格的代码,这应该足以解释该问题。

\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}

这是预览

从图像中可以看出,问题很明显,我希望文本被截断以及分割。

答案1

常见的方式是使用包hyperref,只需用 替换命令即可\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}

结果:

在此处输入图片描述

相关内容