![如何在每行的开始和结束处添加文字?](https://linux22.com/image/435222/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%AF%8F%E8%A1%8C%E7%9A%84%E5%BC%80%E5%A7%8B%E5%92%8C%E7%BB%93%E6%9D%9F%E5%A4%84%E6%B7%BB%E5%8A%A0%E6%96%87%E5%AD%97%EF%BC%9F.png)
我想在每行末尾添加一些文本。例如,对于输入
This is a long text that will be split by LaTeX into various lines.
我想获得
This is a long textX
Xthat will be splitX
Xby LaTeX into variousX
Xlines.
在每行的开始和结束处添加 X。
动机:我想要\hl
从soul
包中用填充包围文本,类似于\colorbox
但能够将文本分成几行:
\newcommand\myHl[1]{{\Large\hl{\normalsize~#1~}}}
(请注意 周围的空格#1
)。但是,当文本被分成几行时,突出显示的跨度不会在行首和行末显示此额外边距:
This is a long text
that will be split
by LaTeX into various
lines.
请注意最开始和最结束处的边距,但内行中没有边距。在每行的开头和结尾添加一个空格将添加所需的边距:
This is a long text
that will be split
by LaTeX into various
lines.
梅威瑟:
\documentclass{article}
\usepackage{color,soul}
\usepackage{array}
\newcommand\myHlWithoutLarge[1]{\hl{~#1~}}
\newcommand\myHlWithLarge[1]{{\Large\hl{\normalsize~#1~}}}
\begin{document}
I want the text to be highlighted \myHlWithLarge{like this} and not \hl{like this}.
\renewcommand\arraystretch{2}
\begin{tabular}{l>{\raggedright\arraybackslash}p{3.8cm}|>{\raggedright\arraybackslash}p{3cm}}
Normal \verb|\hl| & This is \hl{short text} here
& no margin \\
& Now \hl{this is a long text that will be split by LaTeX into various lines} when typeset \\
\verb|\myHlWithoutLarge| & This is \myHlWithoutLarge{short text} here
& left / right margin \\
& Now \myHlWithoutLarge{this is a long text that will be split by LaTeX into various lines} when typeset \\
\verb|\myHlWithLarge| & This is \myHlWithLarge{short text} here
& margin around: what I want \\
& Now \myHlWithLarge{this is a long text that will be split by LaTeX into various lines} when typeset
& but ugly on the inner\- lines!\\
\end{tabular}
\end{document}