![LaTex 如何在文本下标环境中自动换行](https://linux22.com/image/408566/LaTex%20%E5%A6%82%E4%BD%95%E5%9C%A8%E6%96%87%E6%9C%AC%E4%B8%8B%E6%A0%87%E7%8E%AF%E5%A2%83%E4%B8%AD%E8%87%AA%E5%8A%A8%E6%8D%A2%E8%A1%8C.png)
我在用着
\newcommand{\textss}[1]{\textsubscript{\,\underline{#1}}}
做出如下文本注释:
Here are some text\textss{and I made some comments here,
but the text maybe too long to feed a line...}
这里,长下标注释不会自动换行并超出 PDF 边缘。
如何使其自动换行?谢谢。
答案1
从聊天中得出的答案是:不是真正的上标,但很简单。
\documentclass{article}
\usepackage{lipsum}
\usepackage[normalem]{ulem}
\newcommand{\textss}[1]{\,\scriptsize\uline{#1}}
\begin{document}
\lipsum[1-5]
more text and more text and\textss{more text and more text and more text and more text
and more text and more text and more text and
more text and more text and more text and more text
and more text}
\end{document}
这适用于分页符。以下较旧的提案不适用(但为下标)。
这是一个可行的方法。它使用(变体)这个答案测量行的剩余部分。需要编译两次。
\documentclass{article}
\usepackage{soul}
\usepackage{tikzpagenodes}
\makeatletter
\newcommand{\measureremainder}[1]{%based on https://tex.stackexchange.com/a/17808
\begin{tikzpicture}[overlay,remember picture]
\path (0,0) coordinate (aux);
\pgfpointdiff{\pgfpointanchor{aux}{center}}{\pgfpointanchor{current page text area}{east}}
\xdef#1{\the\pgf@x}
\end{tikzpicture}%
}
\makeatother
\newcommand{\textss}[1]{\textsubscript{\,\measureremainder{\myrem}%
\begin{minipage}[t]{\the\dimexpr\myrem-0.5pt}
\scriptsize\ul{#1}
\end{minipage}}}
\begin{document}
Marmots are very good at hibernating\textss{and I made some comments here, but the text maybe too long to feed a line}
and cats do not only write catcode.
\end{document}
附录:尝试采纳您的建议。
\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{tikzpagenodes}
\makeatletter
\newcommand{\measureremainder}[1]{%based on https://tex.stackexchange.com/a/17808
\begin{tikzpicture}[overlay,remember picture]
\path (0,0) coordinate (aux);
\pgfpointdiff{\pgfpointanchor{aux}{center}}{\pgfpointanchor{current page text area}{east}}
\xdef#1{\the\pgf@x}
\end{tikzpicture}%
}
\newcommand{\measurevertdist}[1]{%
\begin{tikzpicture}[overlay,remember picture]
\path (0,0) coordinate (aux1);
\pgfpointdiff{\pgfpointanchor{aux1}{center}}{\pgfpointanchor{aux}{center}}
\xdef#1{\the\pgf@y}
\end{tikzpicture}%
}
\makeatother
\newcommand{\textss}[1]{\textsubscript{\,\measureremainder{\myrem}%
\hspace*{\the\dimexpr-1\linewidth+\myrem+0.5pt}\begin{minipage}[t]{\the\dimexpr\textwidth-1pt}
\hspace*{\the\dimexpr\linewidth-\myrem}\scriptsize\uline{#1}%
\measurevertdist{\mydist}%
\measureremainder{\myrem}%
\end{minipage}}%
\ifdim\mydist>5pt\relax
\\[\the\dimexpr\mydist-\baselineskip]%
\hspace*{\the\dimexpr\linewidth-\myrem-0.5ex}
\else
\hspace*{-\myrem}%
\fi}
\begin{document}
Marmots are very good at hibernating\textss{and I made some comments here, but the text maybe too long to feed a line}
and cats do not only write catcode.
Ducks are very good swimmers\textss{and I made some comments here, but the text maybe too long to feed a line}
and cats do not only write catcode.
Ducks\textss{ducks} pft and more text and more text and more text and more text
and more text and more text and more text.
\end{document}